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,並設為環境變數,SDK 會自動讀取:

# 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"

範例

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

from tdx import Client

with Client() 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 圖資 交通圖層與行政區界線
觀光資訊 台灣好行、景點即時影像、日月潭船班與纜車
長者服務 車站與景區的設施、服務、敬老卡與樂齡套票
定位服務 坐標、地址與里程對應路段,查詢周邊資訊
歷史資料 串流讀取每日動態、資料版本、國道 eTag 統計與交通事故
資料異動 版本差異與異動歷程
即時推播 以 MQTT 接收最新消息與營運通阻
GTFS Realtime 公車動態、到站時間與營運通阻
篩選與分頁 篩選、排序與空間條件
用戶端與快取 非同步查詢、重試、記憶體與磁碟快取
結果與匯出 匯出為 Polars、pandas 或 Arrow 表格
原始 API 與 XML 直接呼叫端點、解析 XML

完整說明見文件網站。

貢獻

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

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


TDX SDK 以 MIT 授權釋出。

Metadata

Release files for tdx-tw 0.2.1

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.2.1
File Size Uploaded Provenance Actions
tdx_tw-0.2.1.tar.gz 148.5 kB Without provenance Details for tdx_tw-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 308.3 kB

Release files / tdx_tw-0.2.1.tar.gz

Download URL tdx_tw-0.2.1.tar.gz
Size 148.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1ed51e7110c84fe5d19c2ad0a3feb1cb7a0042401c05ce9c7ddcdc4dce8e5fd2
BLAKE2b-256 checksum
How to use checksums
fa5ecf77fa8c21450bb14221990792f61b9ba854d0b26757cd2b145b1485cc59
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.2.1-py3-none-any.whl

Download URL tdx_tw-0.2.1-py3-none-any.whl
Size 159.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a1241ec12989e23b75ef7bb21545ba92c5adb7340f338b9d5ab9fb380644974
BLAKE2b-256 checksum
How to use checksums
43092a8bf0f26e913fe4beb00d5e8ed76623d0526a4ad253fe25188dbf89efa8
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.2.1

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