Skip to main content

TDX

臺灣運輸資料流通服務平臺(TDX)的非官方 Python SDK。

CI 套件版本 Python 版本

繁體中文 | English

臺灣運輸資料流通服務平臺(TDX)匯集全臺公共運輸與道路資料。這個 SDK 負責認證、呼叫 API 與驗證回應,並把公車、軌道、自行車、停車、路況、航空、航運等資料整理成有型別的 Python 物件,同步與非同步皆可使用。

安裝

需要 Python 3.13 以上版本。PyPI 套件名稱為 tdx-tw,匯入名稱為 tdx。

pip install tdx-tw

使用 uv 則執行 uv add tdx-tw。匯出表格、座標轉換等選用功能需要額外套件,見選用功能。

設定 API 金鑰

至 TDX 註冊會員,在會員中心取得 API 金鑰的 Client ID 與 Client Secret。範例從環境變數讀取金鑰:

# macOS、Linux
export TDX_CLIENT_ID="Client ID"
export TDX_CLIENT_SECRET="Client Secret"
# Windows PowerShell
$env:TDX_CLIENT_ID = "Client ID"
$env:TDX_CLIENT_SECRET = "Client Secret"

範例

查詢公車路線各站的到站時間:

import os

from tdx import Client

with Client(os.environ["TDX_CLIENT_ID"], os.environ["TDX_CLIENT_SECRET"]) as client:
    for board in client.bus_route("Taipei", "307").board():
        print(board.route_name, board.direction)
        for item in board.stops:
            print(item.stop.name, item.estimate_seconds)

功能

功能 說明
公車 到站預估、站序、班表、票價與車輛動態
軌道 臺鐵、高鐵、捷運的時刻表、票價、座位與即時動態
自行車 租借站與即時借還數量
停車 停車場、路邊停車、即時空位與費率
附近查詢 座標附近的站牌、車站、自行車站與停車場
路況與道路事件 偵測器、攝影機、路段路況、施工與封閉
道路與路段編碼 道路、交流道、路段線型與版本異動
航空 航班看板、班表、國內票價與機場氣象
航運 航線、船班、票價與到離港看板
充電樁 充電站、費率與充電槍即時狀態
GIS 圖資 交通圖層與行政區界線
觀光資訊 台灣好行的路線、班表與即時到站
篩選與分頁 有型別的篩選、排序與空間條件
用戶端與快取 非同步查詢、重試、記憶體與磁碟快取
結果與匯出 匯出為 Polars、pandas 或 Arrow 表格
原始 API 與 XML 直接呼叫端點、解析 XML

完整說明見文件網站。

貢獻

歡迎到 GitHub Issues 回報問題或提出 API 需求。

請見變更紀錄。資料由運輸資料流通服務平臺提供。tdx-tw 為非官方套件,與交通部無關。


TDX SDK 以 MIT 授權釋出。

Metadata

Release files for tdx-tw 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tdx-tw 0.1.2
File Size Uploaded Provenance Actions
tdx_tw-0.1.2.tar.gz 121.5 kB Without provenance Details for tdx_tw-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tdx-tw 0.1.2
File Interpreter ABI Platform Actions
tdx_tw-0.1.2-py3-none-any.whl Python 3 none any Details for tdx_tw-0.1.2-py3-none-any.whl

Total release size: 251.3 kB

Release files / tdx_tw-0.1.2.tar.gz

Download URL tdx_tw-0.1.2.tar.gz
Size 121.5 kB
Tags Source
SHA-256 checksum
How to use checksums
38b787717a0f1bc82754c19d6f6b602c371572f4a8d8bce30a6e7a0774517cca
BLAKE2b-256 checksum
How to use checksums
1d7d51e7cfaeaa43c4505b762f6e8564beb0987be9006d0ec7dbe2b189b40243
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / tdx_tw-0.1.2-py3-none-any.whl

Download URL tdx_tw-0.1.2-py3-none-any.whl
Size 129.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17eb1123a9fbeffd7d6a1ab226bcb331b973fc724c82eddb6c9127bec68f7311
BLAKE2b-256 checksum
How to use checksums
ab7de2321f6b39d6dfec8e513f1632a3582d516eaaf9c085f83554b9d42cf453
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for tdx-tw 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page