motc-tdx-proxy


Namemotc-tdx-proxy JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/chihsuanwu/tdx-proxy
Summary台灣交通部「TDX運輸資料流通服務平臺」之python介接套件
upload_time2024-08-10 03:14:02
maintainerNone
docs_urlNone
authorChi-Hsuan Wu
requires_python<4,>=3.10
licenseNone
keywords tdx
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TDX Proxy

[English docs](https://github.com/chihsuanwu/tdx-proxy/blob/main/README.en.md)

台灣交通部「[TDX運輸資料流通服務平臺](https://tdx.transportdata.tw/)」之python介接套件

TDX Proxy 將與 TDX 平台之介接流程簡化,只要給予 Client ID 與 Secret Key,
便能直接對 TDX 平台之 API 進行呼叫。

TDX Proxy 支援不使用 API 金鑰呼叫 TDX 平台,但含有部分
[限制](https://tdx.transportdata.tw/api-service/swagger),如每個呼叫來源端IP的上限為每日50次等。

一個簡單範例:

```python
from tdx_proxy import TDXProxy

proxy = TDXProxy(app_id=YOUR_TDX_ID, app_key=YOUR_TDX_KEY)

result = proxy.get(TDX_SERVICE_URL)
```

# Installing TDX Proxy

TDX Proxy 可透過 [PyPI](https://pypi.org/project/motc-tdx-proxy/) 安裝

```console
$ pip install motc-tdx-proxy
```

需求 python 3.10+

# Features

- 自動進行身分驗證並取得 **Access Token**
- **Access Token** 快取機制,只在過期或驗證錯誤時再自動重新取得 Token
- 自動處理 [TDX 呼叫頻率限制](https://github.com/tdxmotc/SampleCode#api%E4%BD%BF%E7%94%A8%E6%AC%A1%E6%95%B8%E9%99%90%E5%88%B6)
- 支援不使用 API 金鑰呼叫 TDX 平台 [(含部分限制)](https://tdx.transportdata.tw/api-service/swagger)

# Documentation

## Initialize Proxy

初始化 Proxy 可將 ID 與 KEY 直接作為參數帶入,或使用 credential 檔案

```python
# 直接帶入參數
proxy = TDXProxy(app_id=YOUR_TDX_ID, app_key=YOUR_TDX_KEY)

# 使用 credential 檔案
# file_name 若不指定,將會使用環境變數 TDX_CREDENTIALS_FILE 作為預設路徑
proxy = TDXProxy.from_credential_file(file_name=YOUR_CREDENTAIL_FILE)
```

其中 credential 檔案為 Json 檔,格式如下
```json
{
    "app_id": "YOUR_ID",
    "app_key": "YOUR_KEY"
}
```

也可以不使用 API 金鑰初始化 proxy,但含有部分
[限制](https://tdx.transportdata.tw/api-service/swagger),如每個呼叫來源端IP的上限為每日50次等。

```python
# 不使用 API 金鑰
proxy = TDXProxy.no_auth()
```

## Calling TDX API

使用 `TDXProxy.get()` 呼叫 TDX API,
回傳為 [requests.Response](https://requests.readthedocs.io/en/latest/api/#requests.Response) 物件

```python
result = proxy.get('v3/Rail/TRA/DailyTrainTimetable/TrainDates')
```

### **Parameters:**
- **url** - TDX API URL,不須包含 base 以及 parameter ,如下所述
- **url_base** - (Optional) 預設為 `https://tdx.transportdata.tw/api/basic/`
- **params** - (Optional) Dict,額外的參數,預設為 `{ 'format': 'JSON' }`
- **headers** - (Optional) Dict,額外的 headers 如 `If-Modified-Since`,authorization header 會在呼叫 API 時自動加入

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/chihsuanwu/tdx-proxy",
    "name": "motc-tdx-proxy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.10",
    "maintainer_email": null,
    "keywords": "tdx",
    "author": "Chi-Hsuan Wu",
    "author_email": "chihsuanw@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f9/91/750ba6f810d61c38e4972ad0858e54b1901bc4756aca37b01d9fc0721dd0/motc_tdx_proxy-0.1.1.tar.gz",
    "platform": null,
    "description": "# TDX Proxy\r\n\r\n[English docs](https://github.com/chihsuanwu/tdx-proxy/blob/main/README.en.md)\r\n\r\n\u53f0\u7063\u4ea4\u901a\u90e8\u300c[TDX\u904b\u8f38\u8cc7\u6599\u6d41\u901a\u670d\u52d9\u5e73\u81fa](https://tdx.transportdata.tw/)\u300d\u4e4bpython\u4ecb\u63a5\u5957\u4ef6\r\n\r\nTDX Proxy \u5c07\u8207 TDX \u5e73\u53f0\u4e4b\u4ecb\u63a5\u6d41\u7a0b\u7c21\u5316\uff0c\u53ea\u8981\u7d66\u4e88 Client ID \u8207 Secret Key\uff0c\r\n\u4fbf\u80fd\u76f4\u63a5\u5c0d TDX \u5e73\u53f0\u4e4b API \u9032\u884c\u547c\u53eb\u3002\r\n\r\nTDX Proxy \u652f\u63f4\u4e0d\u4f7f\u7528 API \u91d1\u9470\u547c\u53eb TDX \u5e73\u53f0\uff0c\u4f46\u542b\u6709\u90e8\u5206\r\n[\u9650\u5236](https://tdx.transportdata.tw/api-service/swagger)\uff0c\u5982\u6bcf\u500b\u547c\u53eb\u4f86\u6e90\u7aefIP\u7684\u4e0a\u9650\u70ba\u6bcf\u65e550\u6b21\u7b49\u3002\r\n\r\n\u4e00\u500b\u7c21\u55ae\u7bc4\u4f8b\uff1a\r\n\r\n```python\r\nfrom tdx_proxy import TDXProxy\r\n\r\nproxy = TDXProxy(app_id=YOUR_TDX_ID, app_key=YOUR_TDX_KEY)\r\n\r\nresult = proxy.get(TDX_SERVICE_URL)\r\n```\r\n\r\n# Installing TDX Proxy\r\n\r\nTDX Proxy \u53ef\u900f\u904e [PyPI](https://pypi.org/project/motc-tdx-proxy/) \u5b89\u88dd\r\n\r\n```console\r\n$ pip install motc-tdx-proxy\r\n```\r\n\r\n\u9700\u6c42 python 3.10+\r\n\r\n# Features\r\n\r\n- \u81ea\u52d5\u9032\u884c\u8eab\u5206\u9a57\u8b49\u4e26\u53d6\u5f97 **Access Token**\r\n- **Access Token** \u5feb\u53d6\u6a5f\u5236\uff0c\u53ea\u5728\u904e\u671f\u6216\u9a57\u8b49\u932f\u8aa4\u6642\u518d\u81ea\u52d5\u91cd\u65b0\u53d6\u5f97 Token\r\n- \u81ea\u52d5\u8655\u7406 [TDX \u547c\u53eb\u983b\u7387\u9650\u5236](https://github.com/tdxmotc/SampleCode#api%E4%BD%BF%E7%94%A8%E6%AC%A1%E6%95%B8%E9%99%90%E5%88%B6)\r\n- \u652f\u63f4\u4e0d\u4f7f\u7528 API \u91d1\u9470\u547c\u53eb TDX \u5e73\u53f0 [(\u542b\u90e8\u5206\u9650\u5236)](https://tdx.transportdata.tw/api-service/swagger)\r\n\r\n# Documentation\r\n\r\n## Initialize Proxy\r\n\r\n\u521d\u59cb\u5316 Proxy \u53ef\u5c07 ID \u8207 KEY \u76f4\u63a5\u4f5c\u70ba\u53c3\u6578\u5e36\u5165\uff0c\u6216\u4f7f\u7528 credential \u6a94\u6848\r\n\r\n```python\r\n# \u76f4\u63a5\u5e36\u5165\u53c3\u6578\r\nproxy = TDXProxy(app_id=YOUR_TDX_ID, app_key=YOUR_TDX_KEY)\r\n\r\n# \u4f7f\u7528 credential \u6a94\u6848\r\n# file_name \u82e5\u4e0d\u6307\u5b9a\uff0c\u5c07\u6703\u4f7f\u7528\u74b0\u5883\u8b8a\u6578 TDX_CREDENTIALS_FILE \u4f5c\u70ba\u9810\u8a2d\u8def\u5f91\r\nproxy = TDXProxy.from_credential_file(file_name=YOUR_CREDENTAIL_FILE)\r\n```\r\n\r\n\u5176\u4e2d credential \u6a94\u6848\u70ba Json \u6a94\uff0c\u683c\u5f0f\u5982\u4e0b\r\n```json\r\n{\r\n    \"app_id\": \"YOUR_ID\",\r\n    \"app_key\": \"YOUR_KEY\"\r\n}\r\n```\r\n\r\n\u4e5f\u53ef\u4ee5\u4e0d\u4f7f\u7528 API \u91d1\u9470\u521d\u59cb\u5316 proxy\uff0c\u4f46\u542b\u6709\u90e8\u5206\r\n[\u9650\u5236](https://tdx.transportdata.tw/api-service/swagger)\uff0c\u5982\u6bcf\u500b\u547c\u53eb\u4f86\u6e90\u7aefIP\u7684\u4e0a\u9650\u70ba\u6bcf\u65e550\u6b21\u7b49\u3002\r\n\r\n```python\r\n# \u4e0d\u4f7f\u7528 API \u91d1\u9470\r\nproxy = TDXProxy.no_auth()\r\n```\r\n\r\n## Calling TDX API\r\n\r\n\u4f7f\u7528 `TDXProxy.get()` \u547c\u53eb TDX API\uff0c\r\n\u56de\u50b3\u70ba [requests.Response](https://requests.readthedocs.io/en/latest/api/#requests.Response) \u7269\u4ef6\r\n\r\n```python\r\nresult = proxy.get('v3/Rail/TRA/DailyTrainTimetable/TrainDates')\r\n```\r\n\r\n### **Parameters:**\r\n- **url** - TDX API URL\uff0c\u4e0d\u9808\u5305\u542b base \u4ee5\u53ca parameter \uff0c\u5982\u4e0b\u6240\u8ff0\r\n- **url_base** - (Optional) \u9810\u8a2d\u70ba `https://tdx.transportdata.tw/api/basic/`\r\n- **params** - (Optional) Dict\uff0c\u984d\u5916\u7684\u53c3\u6578\uff0c\u9810\u8a2d\u70ba `{ 'format': 'JSON' }`\r\n- **headers** - (Optional) Dict\uff0c\u984d\u5916\u7684 headers \u5982 `If-Modified-Since`\uff0cauthorization header \u6703\u5728\u547c\u53eb API \u6642\u81ea\u52d5\u52a0\u5165\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u53f0\u7063\u4ea4\u901a\u90e8\u300cTDX\u904b\u8f38\u8cc7\u6599\u6d41\u901a\u670d\u52d9\u5e73\u81fa\u300d\u4e4bpython\u4ecb\u63a5\u5957\u4ef6",
    "version": "0.1.1",
    "project_urls": {
        "Bug Reports": "https://github.com/chihsuanwu/tdx-proxy/issues",
        "Homepage": "https://github.com/chihsuanwu/tdx-proxy",
        "Source": "https://github.com/chihsuanwu/tdx-proxy/"
    },
    "split_keywords": [
        "tdx"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "74808b4eea0e9e1b285f2a21b876cf49b0c005dea2e8bd0609d453f7a19d3a5c",
                "md5": "9b3cdc6d7953a40b3888ea82635c278e",
                "sha256": "d8b846074580a3a7e87171ff0710a6d98706197cb1906a064b2cf5192e2953d1"
            },
            "downloads": -1,
            "filename": "motc_tdx_proxy-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b3cdc6d7953a40b3888ea82635c278e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.10",
            "size": 6007,
            "upload_time": "2024-08-10T03:14:00",
            "upload_time_iso_8601": "2024-08-10T03:14:00.687447Z",
            "url": "https://files.pythonhosted.org/packages/74/80/8b4eea0e9e1b285f2a21b876cf49b0c005dea2e8bd0609d453f7a19d3a5c/motc_tdx_proxy-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f991750ba6f810d61c38e4972ad0858e54b1901bc4756aca37b01d9fc0721dd0",
                "md5": "c2cdc107f6e5d8932bfe3ba3c713407e",
                "sha256": "1f87cba8f1d330ac57750b658ac93e4abaf6d1fa539c96e51e9d24c950225016"
            },
            "downloads": -1,
            "filename": "motc_tdx_proxy-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c2cdc107f6e5d8932bfe3ba3c713407e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.10",
            "size": 6329,
            "upload_time": "2024-08-10T03:14:02",
            "upload_time_iso_8601": "2024-08-10T03:14:02.358692Z",
            "url": "https://files.pythonhosted.org/packages/f9/91/750ba6f810d61c38e4972ad0858e54b1901bc4756aca37b01d9fc0721dd0/motc_tdx_proxy-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-10 03:14:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "chihsuanwu",
    "github_project": "tdx-proxy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "motc-tdx-proxy"
}
        
Elapsed time: 0.45973s