tdx-tw 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tdx_tw-0.1.0/LICENSE +21 -0
- tdx_tw-0.1.0/PKG-INFO +164 -0
- tdx_tw-0.1.0/README.md +108 -0
- tdx_tw-0.1.0/pyproject.toml +164 -0
- tdx_tw-0.1.0/pyproject.toml.orig +139 -0
- tdx_tw-0.1.0/src/tdx/__init__.py +16 -0
- tdx_tw-0.1.0/src/tdx/_auth.py +117 -0
- tdx_tw-0.1.0/src/tdx/_cache.py +76 -0
- tdx_tw-0.1.0/src/tdx/_client.py +458 -0
- tdx_tw-0.1.0/src/tdx/_frames.py +102 -0
- tdx_tw-0.1.0/src/tdx/_http.py +76 -0
- tdx_tw-0.1.0/src/tdx/_service.py +177 -0
- tdx_tw-0.1.0/src/tdx/_transport.py +232 -0
- tdx_tw-0.1.0/src/tdx/administration.py +338 -0
- tdx_tw-0.1.0/src/tdx/air.py +830 -0
- tdx_tw-0.1.0/src/tdx/audible_signals.py +146 -0
- tdx_tw-0.1.0/src/tdx/bike.py +211 -0
- tdx_tw-0.1.0/src/tdx/bus.py +4551 -0
- tdx_tw-0.1.0/src/tdx/charging.py +640 -0
- tdx_tw-0.1.0/src/tdx/exceptions.py +48 -0
- tdx_tw-0.1.0/src/tdx/fields.py +8010 -0
- tdx_tw-0.1.0/src/tdx/gis.py +709 -0
- tdx_tw-0.1.0/src/tdx/models.py +214 -0
- tdx_tw-0.1.0/src/tdx/parking.py +1833 -0
- tdx_tw-0.1.0/src/tdx/py.typed +0 -0
- tdx_tw-0.1.0/src/tdx/query.py +314 -0
- tdx_tw-0.1.0/src/tdx/rail.py +3846 -0
- tdx_tw-0.1.0/src/tdx/resources.py +793 -0
- tdx_tw-0.1.0/src/tdx/road_events.py +280 -0
- tdx_tw-0.1.0/src/tdx/road_links.py +1192 -0
- tdx_tw-0.1.0/src/tdx/road_reference.py +329 -0
- tdx_tw-0.1.0/src/tdx/ship.py +1122 -0
- tdx_tw-0.1.0/src/tdx/tourism.py +677 -0
- tdx_tw-0.1.0/src/tdx/traffic.py +999 -0
- tdx_tw-0.1.0/src/tdx/transport_reference.py +242 -0
- tdx_tw-0.1.0/src/tdx/xml.py +27 -0
tdx_tw-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nolan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tdx_tw-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tdx-tw
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 臺灣運輸資料流通服務平臺(TDX)的 Python SDK
|
|
5
|
+
Keywords: tdx,taiwan,transport,public-transit,odata
|
|
6
|
+
Author: Nolan
|
|
7
|
+
Author-email: Nolan <300344883+nolantw@users.noreply.github.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Dist: anyio
|
|
18
|
+
Requires-Dist: geographiclib
|
|
19
|
+
Requires-Dist: hishel[httpx2]
|
|
20
|
+
Requires-Dist: httpx2[brotli]
|
|
21
|
+
Requires-Dist: pydantic
|
|
22
|
+
Requires-Dist: tenacity
|
|
23
|
+
Requires-Dist: tzdata
|
|
24
|
+
Requires-Dist: tdx-tw[arrow,fast,geo,geohash,gtfs,mqtt,pandas,polars,sqlite,xml] ; extra == 'all'
|
|
25
|
+
Requires-Dist: narwhals ; extra == 'arrow'
|
|
26
|
+
Requires-Dist: pyarrow ; extra == 'arrow'
|
|
27
|
+
Requires-Dist: pyproj ; extra == 'fast'
|
|
28
|
+
Requires-Dist: shapely ; extra == 'geo'
|
|
29
|
+
Requires-Dist: pygeohash ; extra == 'geohash'
|
|
30
|
+
Requires-Dist: gtfs-realtime-bindings ; extra == 'gtfs'
|
|
31
|
+
Requires-Dist: paho-mqtt ; extra == 'mqtt'
|
|
32
|
+
Requires-Dist: narwhals ; extra == 'pandas'
|
|
33
|
+
Requires-Dist: pandas ; extra == 'pandas'
|
|
34
|
+
Requires-Dist: pyarrow ; extra == 'pandas'
|
|
35
|
+
Requires-Dist: narwhals ; extra == 'polars'
|
|
36
|
+
Requires-Dist: polars ; extra == 'polars'
|
|
37
|
+
Requires-Dist: anysqlite ; extra == 'sqlite'
|
|
38
|
+
Requires-Dist: lxml ; extra == 'xml'
|
|
39
|
+
Requires-Dist: pydantic-xml ; extra == 'xml'
|
|
40
|
+
Requires-Python: >=3.13
|
|
41
|
+
Project-URL: Repository, https://github.com/nolantw/tdx
|
|
42
|
+
Project-URL: Issues, https://github.com/nolantw/tdx/issues
|
|
43
|
+
Project-URL: TDX API, https://tdx.transportdata.tw/api-service/swagger/
|
|
44
|
+
Provides-Extra: all
|
|
45
|
+
Provides-Extra: arrow
|
|
46
|
+
Provides-Extra: fast
|
|
47
|
+
Provides-Extra: geo
|
|
48
|
+
Provides-Extra: geohash
|
|
49
|
+
Provides-Extra: gtfs
|
|
50
|
+
Provides-Extra: mqtt
|
|
51
|
+
Provides-Extra: pandas
|
|
52
|
+
Provides-Extra: polars
|
|
53
|
+
Provides-Extra: sqlite
|
|
54
|
+
Provides-Extra: xml
|
|
55
|
+
Description-Content-Type: text/markdown
|
|
56
|
+
|
|
57
|
+
<h1 align="center">TDX</h1>
|
|
58
|
+
|
|
59
|
+
<p align="center">臺灣運輸資料流通服務平臺(TDX)的非官方 Python SDK。</p>
|
|
60
|
+
|
|
61
|
+
<p align="center"><strong>繁體中文</strong> | <a href="https://github.com/nolantw/tdx/blob/HEAD/README.en.md">English</a></p>
|
|
62
|
+
|
|
63
|
+
TDX SDK 提供同步與非同步查詢,可取得公共運輸、道路、停車、充電與 GIS 圖資。
|
|
64
|
+
|
|
65
|
+
## 快速開始
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from tdx import Client, Position, Query, fields
|
|
69
|
+
from tdx.bus import BusStop
|
|
70
|
+
|
|
71
|
+
with Client("CLIENT_ID", "CLIENT_SECRET") as client:
|
|
72
|
+
for board in client.bus_route("Taipei", "307").board(cache_ttl=3600):
|
|
73
|
+
for item in board.stops:
|
|
74
|
+
print(item.stop.name, item.estimate_seconds)
|
|
75
|
+
|
|
76
|
+
for train in client.rail_station("TRA", "1000").trains():
|
|
77
|
+
print(train.departure_time, train.destination, train.delay_minutes)
|
|
78
|
+
|
|
79
|
+
here = Position.at(longitude=121.517, latitude=25.047)
|
|
80
|
+
for place in client.nearby(here, city="Taipei", include=("bike",)).bike_stations:
|
|
81
|
+
print(place.item.station.name, place.item.availability, place.distance)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## 高階操作
|
|
85
|
+
|
|
86
|
+
`Client` 與 `AsyncClient` 提供下列操作,自動挑選端點版本並合併靜態與即時資料。非同步版本在取得資料時使用 `await`。
|
|
87
|
+
|
|
88
|
+
| 操作 | 內容 |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `bus_route(city, name)` | 以完整路線名稱查詢站序、班表、線型、票價、車輛動態;`board()` 合併站序與到站預估 |
|
|
91
|
+
| `rail_station(system, station_id)` | 車站資料、出口、設施、列車、到另一站的班次與票價 |
|
|
92
|
+
| `bike_station(city, station_uid)` | 租借站點與即時借還數量 |
|
|
93
|
+
| `car_park(area, car_park_id)` | 路外停車場與即時空位 |
|
|
94
|
+
| `nearby(position, city=...)` | 座標附近的公車站牌、軌道車站、自行車站與停車場,依距離排序 |
|
|
95
|
+
|
|
96
|
+
`nearby` 每種資料需要一次以上請求,可用 `include` 只選擇需要的種類。
|
|
97
|
+
|
|
98
|
+
## 基礎服務
|
|
99
|
+
|
|
100
|
+
| 資料類別 | 查詢入口 | 主要功能 |
|
|
101
|
+
| --- | --- | --- |
|
|
102
|
+
| 共通資料-行政區 | `administration` | 縣市、鄉鎮市區與村里 |
|
|
103
|
+
| 共通資料-公共運輸 | `transport_reference` | 主管機關、資料提供者、營運業者與行事曆 |
|
|
104
|
+
| 公車 | `bus` | 路線、站序、班表、票價、車輛動態與到站預估 |
|
|
105
|
+
| 軌道 | `rail` | 臺鐵、高鐵、捷運與阿里山林鐵的車站、班表、票價與即時資訊 |
|
|
106
|
+
| 自行車 | `bike` | 租借站點、即時借還數量與自行車道 |
|
|
107
|
+
| 停車資訊 | `parking` | 路外停車場、路邊路段、車格、即時空位與費率 |
|
|
108
|
+
| 共通資料-道路 | `road_reference` | 道路分類、路名、交流道與匝道 |
|
|
109
|
+
| 路況資訊 | `traffic` | 車流偵測器、資訊看板、攝影機、eTag 與即時路況 |
|
|
110
|
+
| 道路事件 | `road_events` | 公告與即時事件、交通管制及改道資訊 |
|
|
111
|
+
| 航空 | `air` | 機場、航班看板、班表、國內票價及 METAR |
|
|
112
|
+
| 航運 | `ship` | 港口、航線、船班、票價、即時船位及到離港看板 |
|
|
113
|
+
| GIS 圖資 | `gis` | 交通圖層、行政區界線、WKT、GeoJSON 與 XML |
|
|
114
|
+
| 路段編碼 | `road_links` | 路段、路口、幾何及版本異動 |
|
|
115
|
+
| 充電樁 | `charging` | 站點、設備、費率與接頭即時狀態 |
|
|
116
|
+
| 觀光資訊 | `tourism` | 台灣好行路線、班表、票價與即時到站 |
|
|
117
|
+
| 有聲號誌 | `audible_signals` | 行人有聲號誌位置、啟動方式與主管機關 |
|
|
118
|
+
|
|
119
|
+
`Client` 與 `AsyncClient` 共用上述查詢入口。`basic` 可直接呼叫指定版本的端點並傳入端點支援的 OData 參數。提供 `cache_ttl` 的查詢預設關閉快取,傳入秒數即可啟用。
|
|
120
|
+
|
|
121
|
+
上游端點及授權方式請見 [TDX 線上 API 說明](https://tdx.transportdata.tw/api-service/swagger/)。
|
|
122
|
+
|
|
123
|
+
## OData 查詢
|
|
124
|
+
|
|
125
|
+
`fields` 涵蓋清單查詢的欄位,包含巢狀欄位與陣列,錯誤的欄位或型別可在執行前由型別檢查器發現。
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
stop = fields.bus_stop
|
|
129
|
+
query = (
|
|
130
|
+
Query[BusStop]()
|
|
131
|
+
.where(stop.name.zh_tw.contains("車站") | stop.name.en.startswith("Main"))
|
|
132
|
+
.near(stop.position, longitude=121.517, latitude=25.047, radius=300)
|
|
133
|
+
.order_by(stop.id.asc())
|
|
134
|
+
)
|
|
135
|
+
stops = client.bus.stops("Taipei", query=query, limit=20)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
陣列欄位使用 `any` 與 `all`,條件以 `&`、`|`、`~` 組合。`query` 也接受原始的 OData 參數。
|
|
139
|
+
|
|
140
|
+
## XML
|
|
141
|
+
|
|
142
|
+
`tdx.xml.parse_xml` 以 pydantic-xml 模型解析 `get_xml` 取得的內容,不展開外部實體,也不存取網路。此功能需要 `xml` 選用相依套件。
|
|
143
|
+
|
|
144
|
+
## 回傳資料
|
|
145
|
+
|
|
146
|
+
清單查詢回傳不可變的 `Records`,`info` 提供更新時間與版本。各類資料共用 `Name`、`Position`、時間與日期型別。
|
|
147
|
+
|
|
148
|
+
`Records` 可用 `to_polars()`、`to_pandas()`、`to_arrow()` 匯出,巢狀欄位以點號命名,例如 `name.zh_tw`。`Position` 提供 `distance_to()`、`to_shapely()` 與 `to_geohash()`。匯出功能需要對應的選用相依套件。
|
|
149
|
+
|
|
150
|
+
## 連線
|
|
151
|
+
|
|
152
|
+
暫時性的連線錯誤、逾時與伺服器錯誤會自動重試,次數由 `retries` 設定。TDX 指定等待時間時會依其等待,權杖失效時會重新取得。所有錯誤皆繼承 `tdx.exceptions.TDXError`。
|
|
153
|
+
|
|
154
|
+
指定 `cache_dir` 可將回應保存在磁碟。之後的查詢會先向 TDX 確認資料是否更新,未更新時不重新下載,確認請求仍計入用量。快取不保存存取權杖。
|
|
155
|
+
|
|
156
|
+
## 貢獻
|
|
157
|
+
|
|
158
|
+
歡迎到 [GitHub Issues](https://github.com/nolantw/tdx/issues) 回報問題或提出 API 需求。
|
|
159
|
+
|
|
160
|
+
資料由[運輸資料流通服務平臺](https://tdx.transportdata.tw/)提供。
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
<p align="center"><i>TDX SDK 以 <a href="https://github.com/nolantw/tdx/blob/HEAD/LICENSE">MIT 授權</a>釋出。</i></p>
|
tdx_tw-0.1.0/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<h1 align="center">TDX</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">臺灣運輸資料流通服務平臺(TDX)的非官方 Python SDK。</p>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>繁體中文</strong> | <a href="https://github.com/nolantw/tdx/blob/HEAD/README.en.md">English</a></p>
|
|
6
|
+
|
|
7
|
+
TDX SDK 提供同步與非同步查詢,可取得公共運輸、道路、停車、充電與 GIS 圖資。
|
|
8
|
+
|
|
9
|
+
## 快速開始
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from tdx import Client, Position, Query, fields
|
|
13
|
+
from tdx.bus import BusStop
|
|
14
|
+
|
|
15
|
+
with Client("CLIENT_ID", "CLIENT_SECRET") as client:
|
|
16
|
+
for board in client.bus_route("Taipei", "307").board(cache_ttl=3600):
|
|
17
|
+
for item in board.stops:
|
|
18
|
+
print(item.stop.name, item.estimate_seconds)
|
|
19
|
+
|
|
20
|
+
for train in client.rail_station("TRA", "1000").trains():
|
|
21
|
+
print(train.departure_time, train.destination, train.delay_minutes)
|
|
22
|
+
|
|
23
|
+
here = Position.at(longitude=121.517, latitude=25.047)
|
|
24
|
+
for place in client.nearby(here, city="Taipei", include=("bike",)).bike_stations:
|
|
25
|
+
print(place.item.station.name, place.item.availability, place.distance)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 高階操作
|
|
29
|
+
|
|
30
|
+
`Client` 與 `AsyncClient` 提供下列操作,自動挑選端點版本並合併靜態與即時資料。非同步版本在取得資料時使用 `await`。
|
|
31
|
+
|
|
32
|
+
| 操作 | 內容 |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `bus_route(city, name)` | 以完整路線名稱查詢站序、班表、線型、票價、車輛動態;`board()` 合併站序與到站預估 |
|
|
35
|
+
| `rail_station(system, station_id)` | 車站資料、出口、設施、列車、到另一站的班次與票價 |
|
|
36
|
+
| `bike_station(city, station_uid)` | 租借站點與即時借還數量 |
|
|
37
|
+
| `car_park(area, car_park_id)` | 路外停車場與即時空位 |
|
|
38
|
+
| `nearby(position, city=...)` | 座標附近的公車站牌、軌道車站、自行車站與停車場,依距離排序 |
|
|
39
|
+
|
|
40
|
+
`nearby` 每種資料需要一次以上請求,可用 `include` 只選擇需要的種類。
|
|
41
|
+
|
|
42
|
+
## 基礎服務
|
|
43
|
+
|
|
44
|
+
| 資料類別 | 查詢入口 | 主要功能 |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| 共通資料-行政區 | `administration` | 縣市、鄉鎮市區與村里 |
|
|
47
|
+
| 共通資料-公共運輸 | `transport_reference` | 主管機關、資料提供者、營運業者與行事曆 |
|
|
48
|
+
| 公車 | `bus` | 路線、站序、班表、票價、車輛動態與到站預估 |
|
|
49
|
+
| 軌道 | `rail` | 臺鐵、高鐵、捷運與阿里山林鐵的車站、班表、票價與即時資訊 |
|
|
50
|
+
| 自行車 | `bike` | 租借站點、即時借還數量與自行車道 |
|
|
51
|
+
| 停車資訊 | `parking` | 路外停車場、路邊路段、車格、即時空位與費率 |
|
|
52
|
+
| 共通資料-道路 | `road_reference` | 道路分類、路名、交流道與匝道 |
|
|
53
|
+
| 路況資訊 | `traffic` | 車流偵測器、資訊看板、攝影機、eTag 與即時路況 |
|
|
54
|
+
| 道路事件 | `road_events` | 公告與即時事件、交通管制及改道資訊 |
|
|
55
|
+
| 航空 | `air` | 機場、航班看板、班表、國內票價及 METAR |
|
|
56
|
+
| 航運 | `ship` | 港口、航線、船班、票價、即時船位及到離港看板 |
|
|
57
|
+
| GIS 圖資 | `gis` | 交通圖層、行政區界線、WKT、GeoJSON 與 XML |
|
|
58
|
+
| 路段編碼 | `road_links` | 路段、路口、幾何及版本異動 |
|
|
59
|
+
| 充電樁 | `charging` | 站點、設備、費率與接頭即時狀態 |
|
|
60
|
+
| 觀光資訊 | `tourism` | 台灣好行路線、班表、票價與即時到站 |
|
|
61
|
+
| 有聲號誌 | `audible_signals` | 行人有聲號誌位置、啟動方式與主管機關 |
|
|
62
|
+
|
|
63
|
+
`Client` 與 `AsyncClient` 共用上述查詢入口。`basic` 可直接呼叫指定版本的端點並傳入端點支援的 OData 參數。提供 `cache_ttl` 的查詢預設關閉快取,傳入秒數即可啟用。
|
|
64
|
+
|
|
65
|
+
上游端點及授權方式請見 [TDX 線上 API 說明](https://tdx.transportdata.tw/api-service/swagger/)。
|
|
66
|
+
|
|
67
|
+
## OData 查詢
|
|
68
|
+
|
|
69
|
+
`fields` 涵蓋清單查詢的欄位,包含巢狀欄位與陣列,錯誤的欄位或型別可在執行前由型別檢查器發現。
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
stop = fields.bus_stop
|
|
73
|
+
query = (
|
|
74
|
+
Query[BusStop]()
|
|
75
|
+
.where(stop.name.zh_tw.contains("車站") | stop.name.en.startswith("Main"))
|
|
76
|
+
.near(stop.position, longitude=121.517, latitude=25.047, radius=300)
|
|
77
|
+
.order_by(stop.id.asc())
|
|
78
|
+
)
|
|
79
|
+
stops = client.bus.stops("Taipei", query=query, limit=20)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
陣列欄位使用 `any` 與 `all`,條件以 `&`、`|`、`~` 組合。`query` 也接受原始的 OData 參數。
|
|
83
|
+
|
|
84
|
+
## XML
|
|
85
|
+
|
|
86
|
+
`tdx.xml.parse_xml` 以 pydantic-xml 模型解析 `get_xml` 取得的內容,不展開外部實體,也不存取網路。此功能需要 `xml` 選用相依套件。
|
|
87
|
+
|
|
88
|
+
## 回傳資料
|
|
89
|
+
|
|
90
|
+
清單查詢回傳不可變的 `Records`,`info` 提供更新時間與版本。各類資料共用 `Name`、`Position`、時間與日期型別。
|
|
91
|
+
|
|
92
|
+
`Records` 可用 `to_polars()`、`to_pandas()`、`to_arrow()` 匯出,巢狀欄位以點號命名,例如 `name.zh_tw`。`Position` 提供 `distance_to()`、`to_shapely()` 與 `to_geohash()`。匯出功能需要對應的選用相依套件。
|
|
93
|
+
|
|
94
|
+
## 連線
|
|
95
|
+
|
|
96
|
+
暫時性的連線錯誤、逾時與伺服器錯誤會自動重試,次數由 `retries` 設定。TDX 指定等待時間時會依其等待,權杖失效時會重新取得。所有錯誤皆繼承 `tdx.exceptions.TDXError`。
|
|
97
|
+
|
|
98
|
+
指定 `cache_dir` 可將回應保存在磁碟。之後的查詢會先向 TDX 確認資料是否更新,未更新時不重新下載,確認請求仍計入用量。快取不保存存取權杖。
|
|
99
|
+
|
|
100
|
+
## 貢獻
|
|
101
|
+
|
|
102
|
+
歡迎到 [GitHub Issues](https://github.com/nolantw/tdx/issues) 回報問題或提出 API 需求。
|
|
103
|
+
|
|
104
|
+
資料由[運輸資料流通服務平臺](https://tdx.transportdata.tw/)提供。
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
<p align="center"><i>TDX SDK 以 <a href="https://github.com/nolantw/tdx/blob/HEAD/LICENSE">MIT 授權</a>釋出。</i></p>
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tdx-tw"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "臺灣運輸資料流通服務平臺(TDX)的 Python SDK"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.13"
|
|
9
|
+
keywords = [
|
|
10
|
+
"tdx",
|
|
11
|
+
"taiwan",
|
|
12
|
+
"transport",
|
|
13
|
+
"public-transit",
|
|
14
|
+
"odata",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Programming Language :: Python :: 3.15",
|
|
23
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"anyio",
|
|
27
|
+
"geographiclib",
|
|
28
|
+
"hishel[httpx2]",
|
|
29
|
+
"httpx2[brotli]",
|
|
30
|
+
"pydantic",
|
|
31
|
+
"tenacity",
|
|
32
|
+
"tzdata",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[[project.authors]]
|
|
36
|
+
name = "Nolan"
|
|
37
|
+
email = "300344883+nolantw@users.noreply.github.com"
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
polars = [
|
|
41
|
+
"narwhals",
|
|
42
|
+
"polars",
|
|
43
|
+
]
|
|
44
|
+
pandas = [
|
|
45
|
+
"narwhals",
|
|
46
|
+
"pandas",
|
|
47
|
+
"pyarrow",
|
|
48
|
+
]
|
|
49
|
+
arrow = [
|
|
50
|
+
"narwhals",
|
|
51
|
+
"pyarrow",
|
|
52
|
+
]
|
|
53
|
+
fast = ["pyproj"]
|
|
54
|
+
geo = ["shapely"]
|
|
55
|
+
geohash = ["pygeohash"]
|
|
56
|
+
xml = [
|
|
57
|
+
"lxml",
|
|
58
|
+
"pydantic-xml",
|
|
59
|
+
]
|
|
60
|
+
sqlite = ["anysqlite"]
|
|
61
|
+
mqtt = ["paho-mqtt"]
|
|
62
|
+
gtfs = ["gtfs-realtime-bindings"]
|
|
63
|
+
all = ["tdx-tw[arrow,fast,geo,geohash,gtfs,mqtt,pandas,polars,sqlite,xml]"]
|
|
64
|
+
|
|
65
|
+
[project.urls]
|
|
66
|
+
Repository = "https://github.com/nolantw/tdx"
|
|
67
|
+
Issues = "https://github.com/nolantw/tdx/issues"
|
|
68
|
+
"TDX API" = "https://tdx.transportdata.tw/api-service/swagger/"
|
|
69
|
+
|
|
70
|
+
[build-system]
|
|
71
|
+
requires = ["uv_build>=0.13.10,<0.14.0"]
|
|
72
|
+
build-backend = "uv_build"
|
|
73
|
+
|
|
74
|
+
[tool.uv.build-backend]
|
|
75
|
+
module-name = "tdx"
|
|
76
|
+
|
|
77
|
+
[tool.ruff]
|
|
78
|
+
target-version = "py313"
|
|
79
|
+
|
|
80
|
+
[tool.ruff.lint]
|
|
81
|
+
select = [
|
|
82
|
+
"E4",
|
|
83
|
+
"E7",
|
|
84
|
+
"E9",
|
|
85
|
+
"F",
|
|
86
|
+
"I",
|
|
87
|
+
"UP",
|
|
88
|
+
"B",
|
|
89
|
+
"RUF",
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
[tool.pyright]
|
|
93
|
+
include = [
|
|
94
|
+
"src",
|
|
95
|
+
"tests",
|
|
96
|
+
"scripts",
|
|
97
|
+
]
|
|
98
|
+
pythonVersion = "3.13"
|
|
99
|
+
typeCheckingMode = "strict"
|
|
100
|
+
|
|
101
|
+
[tool.mypy]
|
|
102
|
+
mypy_path = "typings"
|
|
103
|
+
files = [
|
|
104
|
+
"src",
|
|
105
|
+
"tests",
|
|
106
|
+
"scripts",
|
|
107
|
+
]
|
|
108
|
+
python_version = "3.13"
|
|
109
|
+
strict = true
|
|
110
|
+
|
|
111
|
+
[tool.pyrefly]
|
|
112
|
+
project-includes = [
|
|
113
|
+
"src",
|
|
114
|
+
"tests",
|
|
115
|
+
"scripts",
|
|
116
|
+
]
|
|
117
|
+
python-version = "3.13"
|
|
118
|
+
|
|
119
|
+
[tool.ty.environment]
|
|
120
|
+
python-version = "3.13"
|
|
121
|
+
|
|
122
|
+
[tool.pytest.ini_options]
|
|
123
|
+
testpaths = ["tests"]
|
|
124
|
+
addopts = "--strict-markers --allow-hosts=127.0.0.1,::1"
|
|
125
|
+
xfail_strict = true
|
|
126
|
+
|
|
127
|
+
[tool.coverage.run]
|
|
128
|
+
branch = true
|
|
129
|
+
source = ["tdx"]
|
|
130
|
+
|
|
131
|
+
[tool.coverage.report]
|
|
132
|
+
show_missing = true
|
|
133
|
+
|
|
134
|
+
[dependency-groups]
|
|
135
|
+
lint = ["ruff"]
|
|
136
|
+
typing = [
|
|
137
|
+
"lxml-stubs>=0.5.1",
|
|
138
|
+
"mypy",
|
|
139
|
+
"pandas-stubs",
|
|
140
|
+
"pyarrow-stubs",
|
|
141
|
+
"pyrefly",
|
|
142
|
+
"pyright",
|
|
143
|
+
"ty",
|
|
144
|
+
"types-shapely",
|
|
145
|
+
]
|
|
146
|
+
test = [
|
|
147
|
+
"hypothesis",
|
|
148
|
+
"pytest",
|
|
149
|
+
"pytest-cov",
|
|
150
|
+
"pytest-socket",
|
|
151
|
+
]
|
|
152
|
+
packaging = ["twine"]
|
|
153
|
+
|
|
154
|
+
[[dependency-groups.dev]]
|
|
155
|
+
include-group = "lint"
|
|
156
|
+
|
|
157
|
+
[[dependency-groups.dev]]
|
|
158
|
+
include-group = "typing"
|
|
159
|
+
|
|
160
|
+
[[dependency-groups.dev]]
|
|
161
|
+
include-group = "test"
|
|
162
|
+
|
|
163
|
+
[[dependency-groups.dev]]
|
|
164
|
+
include-group = "packaging"
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tdx-tw"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "臺灣運輸資料流通服務平臺(TDX)的 Python SDK"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Nolan", email = "300344883+nolantw@users.noreply.github.com" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.13"
|
|
12
|
+
keywords = ["tdx", "taiwan", "transport", "public-transit", "odata"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Programming Language :: Python :: 3.14",
|
|
19
|
+
"Programming Language :: Python :: 3.15",
|
|
20
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"anyio",
|
|
24
|
+
"geographiclib",
|
|
25
|
+
"hishel[httpx2]",
|
|
26
|
+
"httpx2[brotli]",
|
|
27
|
+
"pydantic",
|
|
28
|
+
"tenacity",
|
|
29
|
+
"tzdata",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
polars = [
|
|
34
|
+
"narwhals",
|
|
35
|
+
"polars",
|
|
36
|
+
]
|
|
37
|
+
pandas = [
|
|
38
|
+
"narwhals",
|
|
39
|
+
"pandas",
|
|
40
|
+
"pyarrow",
|
|
41
|
+
]
|
|
42
|
+
arrow = [
|
|
43
|
+
"narwhals",
|
|
44
|
+
"pyarrow",
|
|
45
|
+
]
|
|
46
|
+
fast = [
|
|
47
|
+
"pyproj",
|
|
48
|
+
]
|
|
49
|
+
geo = [
|
|
50
|
+
"shapely",
|
|
51
|
+
]
|
|
52
|
+
geohash = [
|
|
53
|
+
"pygeohash",
|
|
54
|
+
]
|
|
55
|
+
xml = [
|
|
56
|
+
"lxml",
|
|
57
|
+
"pydantic-xml",
|
|
58
|
+
]
|
|
59
|
+
sqlite = [
|
|
60
|
+
"anysqlite",
|
|
61
|
+
]
|
|
62
|
+
mqtt = [
|
|
63
|
+
"paho-mqtt",
|
|
64
|
+
]
|
|
65
|
+
gtfs = [
|
|
66
|
+
"gtfs-realtime-bindings",
|
|
67
|
+
]
|
|
68
|
+
all = [
|
|
69
|
+
"tdx-tw[arrow,fast,geo,geohash,gtfs,mqtt,pandas,polars,sqlite,xml]",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[project.urls]
|
|
73
|
+
Repository = "https://github.com/nolantw/tdx"
|
|
74
|
+
Issues = "https://github.com/nolantw/tdx/issues"
|
|
75
|
+
"TDX API" = "https://tdx.transportdata.tw/api-service/swagger/"
|
|
76
|
+
|
|
77
|
+
[build-system]
|
|
78
|
+
requires = ["uv_build>=0.13.10,<0.14.0"]
|
|
79
|
+
build-backend = "uv_build"
|
|
80
|
+
|
|
81
|
+
[tool.uv.build-backend]
|
|
82
|
+
module-name = "tdx"
|
|
83
|
+
|
|
84
|
+
[dependency-groups]
|
|
85
|
+
lint = ["ruff"]
|
|
86
|
+
typing = [
|
|
87
|
+
"lxml-stubs>=0.5.1",
|
|
88
|
+
"mypy",
|
|
89
|
+
"pandas-stubs",
|
|
90
|
+
"pyarrow-stubs",
|
|
91
|
+
"pyrefly",
|
|
92
|
+
"pyright",
|
|
93
|
+
"ty",
|
|
94
|
+
"types-shapely",
|
|
95
|
+
]
|
|
96
|
+
test = ["hypothesis", "pytest", "pytest-cov", "pytest-socket"]
|
|
97
|
+
packaging = ["twine"]
|
|
98
|
+
dev = [
|
|
99
|
+
{ include-group = "lint" },
|
|
100
|
+
{ include-group = "typing" },
|
|
101
|
+
{ include-group = "test" },
|
|
102
|
+
{ include-group = "packaging" },
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
[tool.ruff]
|
|
106
|
+
target-version = "py313"
|
|
107
|
+
|
|
108
|
+
[tool.ruff.lint]
|
|
109
|
+
select = ["E4", "E7", "E9", "F", "I", "UP", "B", "RUF"]
|
|
110
|
+
|
|
111
|
+
[tool.pyright]
|
|
112
|
+
include = ["src", "tests", "scripts"]
|
|
113
|
+
pythonVersion = "3.13"
|
|
114
|
+
typeCheckingMode = "strict"
|
|
115
|
+
|
|
116
|
+
[tool.mypy]
|
|
117
|
+
mypy_path = "typings"
|
|
118
|
+
files = ["src", "tests", "scripts"]
|
|
119
|
+
python_version = "3.13"
|
|
120
|
+
strict = true
|
|
121
|
+
|
|
122
|
+
[tool.pyrefly]
|
|
123
|
+
project-includes = ["src", "tests", "scripts"]
|
|
124
|
+
python-version = "3.13"
|
|
125
|
+
|
|
126
|
+
[tool.ty.environment]
|
|
127
|
+
python-version = "3.13"
|
|
128
|
+
|
|
129
|
+
[tool.pytest.ini_options]
|
|
130
|
+
testpaths = ["tests"]
|
|
131
|
+
addopts = "--strict-markers --allow-hosts=127.0.0.1,::1"
|
|
132
|
+
xfail_strict = true
|
|
133
|
+
|
|
134
|
+
[tool.coverage.run]
|
|
135
|
+
branch = true
|
|
136
|
+
source = ["tdx"]
|
|
137
|
+
|
|
138
|
+
[tool.coverage.report]
|
|
139
|
+
show_missing = true
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Python SDK for the Transport Data eXchange (TDX)."""
|
|
2
|
+
|
|
3
|
+
from . import fields
|
|
4
|
+
from ._client import AsyncClient, Client
|
|
5
|
+
from .models import Name, Position, Records
|
|
6
|
+
from .query import Query
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"AsyncClient",
|
|
10
|
+
"Client",
|
|
11
|
+
"Name",
|
|
12
|
+
"Position",
|
|
13
|
+
"Query",
|
|
14
|
+
"Records",
|
|
15
|
+
"fields",
|
|
16
|
+
]
|