Metadata-Version: 2.4
Name: tdx-tw
Version: 0.2.1
Summary: 臺灣運輸資料流通服務平臺（TDX）的 Python SDK
Keywords: tdx,taiwan,transport,public-transit,odata
Author: Nolan
Author-email: Nolan <300344883+nolantw@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: anyio>=4.16.0
Requires-Dist: geographiclib>=2.1
Requires-Dist: hishel[httpx2]>=2.0.0
Requires-Dist: httpx2[brotli]>=2.16.2
Requires-Dist: pydantic>=2.14.4
Requires-Dist: tenacity>=9.2.1
Requires-Dist: tzdata>=2026.6
Requires-Dist: tdx-tw[arrow,fast,geo,geohash,gtfs,mqtt,pandas,polars,xml] ; extra == 'all'
Requires-Dist: narwhals>=2.29.0 ; extra == 'arrow'
Requires-Dist: pyarrow>=26.0.1 ; extra == 'arrow'
Requires-Dist: pyproj>=3.8.0 ; extra == 'fast'
Requires-Dist: shapely>=2.2.0 ; extra == 'geo'
Requires-Dist: pygeohash>=3.6.0 ; extra == 'geohash'
Requires-Dist: gtfs-realtime-bindings>=3.0.0 ; extra == 'gtfs'
Requires-Dist: paho-mqtt>=2.2.0 ; extra == 'mqtt'
Requires-Dist: narwhals>=2.29.0 ; extra == 'pandas'
Requires-Dist: pandas>=3.1.1 ; extra == 'pandas'
Requires-Dist: pyarrow>=26.0.1 ; extra == 'pandas'
Requires-Dist: narwhals>=2.29.0 ; extra == 'polars'
Requires-Dist: polars>=2.2.0 ; extra == 'polars'
Requires-Dist: lxml>=6.2.0 ; extra == 'xml'
Requires-Dist: pydantic-xml>=2.22.0 ; extra == 'xml'
Requires-Python: >=3.13
Project-URL: Documentation, https://nolantw.github.io/tdx/
Project-URL: Repository, https://github.com/nolantw/tdx
Project-URL: Issues, https://github.com/nolantw/tdx/issues
Project-URL: Changelog, https://github.com/nolantw/tdx/blob/main/CHANGELOG.md
Project-URL: TDX API, https://tdx.transportdata.tw/api-service/swagger/
Provides-Extra: all
Provides-Extra: arrow
Provides-Extra: fast
Provides-Extra: geo
Provides-Extra: geohash
Provides-Extra: gtfs
Provides-Extra: mqtt
Provides-Extra: pandas
Provides-Extra: polars
Provides-Extra: xml
Description-Content-Type: text/markdown

<h1 align="center">TDX</h1>

<p align="center">臺灣運輸資料流通服務平臺（TDX）的非官方 Python SDK。</p>

<p align="center">
<a href="https://github.com/nolantw/tdx/actions/workflows/ci.yml"><img src="https://github.com/nolantw/tdx/actions/workflows/ci.yml/badge.svg?branch=dev" alt="CI"></a>
<a href="https://pypi.org/project/tdx-tw/"><img src="https://img.shields.io/pypi/v/tdx-tw.svg" alt="套件版本"></a>
<a href="https://pypi.org/project/tdx-tw/"><img src="https://img.shields.io/pypi/pyversions/tdx-tw.svg" alt="Python 版本"></a>
</p>

<p align="center"><strong>繁體中文</strong> | <a href="https://github.com/nolantw/tdx/blob/main/README.en.md">English</a></p>

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

## 安裝

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

```shell
pip install tdx-tw
```

使用 uv 則執行 `uv add tdx-tw`。匯出表格、座標轉換等選用功能需要額外套件，見[選用功能](https://nolantw.github.io/tdx/#選用功能)。

## 設定 API 金鑰

至 [TDX](https://tdx.transportdata.tw/) 註冊會員，在會員中心取得 API 金鑰的 Client ID 與 Client Secret，並設為環境變數，SDK 會自動讀取：

```shell
# macOS、Linux
export TDX_CLIENT_ID="Client ID"
export TDX_CLIENT_SECRET="Client Secret"
```

```powershell
# Windows PowerShell
$env:TDX_CLIENT_ID = "Client ID"
$env:TDX_CLIENT_SECRET = "Client Secret"
```

## 範例

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

```python
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)
```

## 功能

| 功能 | 說明 |
| --- | --- |
| [公車](https://nolantw.github.io/tdx/guides/bus) | 到站預估、站序、班表、票價與車輛動態 |
| [軌道](https://nolantw.github.io/tdx/guides/rail) | 臺鐵、高鐵、捷運的時刻表、票價、座位與即時動態 |
| [自行車](https://nolantw.github.io/tdx/guides/bike) | 租借站與即時借還數量 |
| [停車](https://nolantw.github.io/tdx/guides/parking) | 停車場、路邊停車、即時空位與費率 |
| [附近查詢](https://nolantw.github.io/tdx/guides/nearby) | 座標附近的站牌、車站、自行車站與停車場 |
| [路線規劃](https://nolantw.github.io/tdx/guides/routing) | 結合公共運輸、步行、自行車與開車的路線 |
| [路況與道路事件](https://nolantw.github.io/tdx/guides/traffic) | 偵測器、攝影機、路段路況、施工與封閉 |
| [道路與路段編碼](https://nolantw.github.io/tdx/guides/roads) | 道路、交流道、路段線型與版本異動 |
| [航空](https://nolantw.github.io/tdx/guides/air) | 航班看板、班表、國內票價與機場氣象 |
| [航運](https://nolantw.github.io/tdx/guides/ship) | 航線、船班、票價與到離港看板 |
| [充電樁](https://nolantw.github.io/tdx/guides/charging) | 充電站、費率與充電槍即時狀態 |
| [GIS 圖資](https://nolantw.github.io/tdx/guides/gis) | 交通圖層與行政區界線 |
| [觀光資訊](https://nolantw.github.io/tdx/guides/tourism) | 台灣好行、景點即時影像、日月潭船班與纜車 |
| [長者服務](https://nolantw.github.io/tdx/guides/seniors) | 車站與景區的設施、服務、敬老卡與樂齡套票 |
| [定位服務](https://nolantw.github.io/tdx/guides/locating) | 坐標、地址與里程對應路段，查詢周邊資訊 |
| [歷史資料](https://nolantw.github.io/tdx/guides/historical) | 串流讀取每日動態、資料版本、國道 eTag 統計與交通事故 |
| [資料異動](https://nolantw.github.io/tdx/guides/changes) | 版本差異與異動歷程 |
| [即時推播](https://nolantw.github.io/tdx/guides/mqtt) | 以 MQTT 接收最新消息與營運通阻 |
| [GTFS Realtime](https://nolantw.github.io/tdx/guides/gtfs) | 公車動態、到站時間與營運通阻 |
| [篩選與分頁](https://nolantw.github.io/tdx/advanced/queries) | 篩選、排序與空間條件 |
| [用戶端與快取](https://nolantw.github.io/tdx/advanced/clients) | 非同步查詢、重試、記憶體與磁碟快取 |
| [結果與匯出](https://nolantw.github.io/tdx/advanced/results) | 匯出為 Polars、pandas 或 Arrow 表格 |
| [原始 API 與 XML](https://nolantw.github.io/tdx/advanced/raw) | 直接呼叫端點、解析 XML |

完整說明見[文件網站](https://nolantw.github.io/tdx/)。

## 貢獻

歡迎到 [GitHub Issues](https://github.com/nolantw/tdx/issues) 回報問題或提出 API 需求。

請見[變更紀錄](https://github.com/nolantw/tdx/blob/main/CHANGELOG.md)。資料由[運輸資料流通服務平臺](https://tdx.transportdata.tw/)提供。tdx-tw 為非官方套件，與交通部無關。

---

<p align="center"><i>TDX SDK 以 <a href="https://github.com/nolantw/tdx/blob/main/LICENSE">MIT 授權</a>釋出。</i></p>
