# 歷史資料 (https://nolantw.github.io/tdx/guides/historical/)

每日資料與交通事故邊下載邊逐筆讀取，不會將整份內容載入記憶體。

## 每日資料

`Archives` 的資料以日期查詢，一次最多 7 天：

```python
from datetime import date

from tdx.historical import Archives

archive = Archives.bike_availability("Taipei")

for bike in client.historical.daily(archive, date(2026, 11, 1), date(2026, 11, 3)):
    print(bike.uid, bike.updated_at)
```

| 名稱 | 內容 |
| --- | --- |
| `bike_availability` | 自行車站的即時數量 |
| `bus_positions` | 公車定時動態，縣市傳入 `None` 則為公路客運 |
| `bus_stop_events` | 公車到離站動態，縣市傳入 `None` 則為公路客運 |
| `bus_news` | 公車最新消息，縣市傳入 `None` 則為公路客運 |
| `detectors` | 車輛偵測器 |
| `detector_observations` | 車輛偵測器的觀測 |
| `message_signs` | 資訊可變標誌 |
| `sign_observations` | 資訊可變標誌的內容 |
| `cameras` | 路況攝影機 |
| `etag_gantries` | eTag 偵測站 |
| `etag_pairs` | eTag 配對路徑 |
| `etag_observations` | eTag 配對路徑的觀測 |
| `sections` | 路況路段 |
| `section_links` | 路況路段的基礎路段 |
| `section_shapes` | 路況路段線型 |
| `congestion_scales` | 壅塞水準 |
| `section_observations` | 路段的路況 |
| `air_departures` | 離站航班 |
| `air_arrivals` | 到站航班 |
| `flights` | 航班動態 |
| `airport_weather` | 機場氣象 |
| `tourist_shuttle_positions` | 台灣好行定時動態 |
| `tourist_shuttle_stop_events` | 台灣好行到離站動態 |
| `tourist_shuttle_news` | 台灣好行最新消息 |
| `car_park_availability` | 路外停車場的剩餘車位 |
| `street_segment_availability` | 路邊停車路段的剩餘車位 |
| `street_spot_availability` | 路邊停車格的狀態 |
| `railway_boards` | 臺鐵到離站看板 |
| `railway_delays` | 臺鐵列車延誤時間 |
| `high_speed_alerts` | 高鐵營運通阻 |
| `high_speed_news` | 高鐵最新消息 |
| `metro_boards` | 捷運列車到站看板 |
| `metro_news` | 捷運最新消息 |
| `metro_alerts` | 捷運營運通阻 |
| `etag_volumes` | 各類車種通行量（M03A） |
| `etag_travel_times` | 站間旅行時間中位數（M04A） |
| `etag_speeds` | 站間行駛車速中位數（M05A） |
| `etag_trips` | 各旅次路徑（M06A） |
| `etag_trip_lengths` | 旅次平均長度（M07A） |
| `etag_trip_counts` | 旅次數量（M08A） |
| `weather_hazards` | 天氣警特報 |
| `weather_stations` | 氣象站觀測 |
| `automatic_weather_stations` | 自動氣象站觀測 |

`AsyncClient` 以 `async for` 讀取。提早離開迴圈時以 `contextlib.aclosing` 關閉下載。

## 資料版本

`Snapshots` 的資料可取得指定日期的內容，或列出期間內的版本：

```python
from datetime import date

from tdx.historical import Snapshots

routes = Snapshots.bus_routes("Taipei")

for version in client.historical.versions(routes, date(2026, 10, 1), date(2026, 11, 1)):
    print(version.version, version.start)

for route in client.historical.snapshot(routes, date(2026, 11, 1)):
    print(route.name)
```

| 名稱 | 內容 |
| --- | --- |
| `bus_stops` | 公車站牌，縣市傳入 `None` 則為公路客運 |
| `bus_stations` | 公車站位，縣市傳入 `None` 則為公路客運 |
| `bus_routes` | 公車路線，縣市傳入 `None` 則為公路客運 |
| `bus_fares` | 公車票價，不含六都、基隆市、澎湖縣與連江縣，縣市傳入 `None` 則為公路客運 |
| `bus_schedules` | 公車定期班表，縣市傳入 `None` 則為公路客運 |
| `bus_shapes` | 公車路線線型，縣市傳入 `None` 則為公路客運 |
| `bus_station_groups` | 公車組站位，不含六都、基隆市、金門縣與連江縣，縣市傳入 `None` 則為公路客運 |
| `bus_route_stops` | 公車路線站序，縣市傳入 `None` 則為公路客運 |
| `bus_display_stops` | 公車顯示用路線站序 |
| `bus_first_last_trips` | 公車首末班車 |
| `intercity_daily_timetables` | 公路客運當日班表 |
| `bike_stations` | 自行車租借站 |
| `airports` | 機場 |
| `airlines` | 航空公司 |
| `domestic_flights` | 國內定期航班 |
| `international_flights` | 國際定期航班 |
| `metro_first_last` | 捷運首末班車 |
| `metro_frequencies` | 捷運發車頻率 |
| `metro_lines` | 捷運路線 |
| `metro_line_transfers` | 捷運路線轉乘 |
| `metro_shapes` | 捷運路線線型 |
| `metro_networks` | 捷運路網 |
| `metro_fares` | 捷運票價 |
| `metro_routes` | 捷運營運路線 |
| `metro_travel_times` | 捷運站間行駛時間 |
| `metro_stations` | 捷運車站 |
| `metro_exits` | 捷運車站出入口 |
| `metro_facilities` | 捷運車站設施 |
| `metro_line_stations` | 捷運路線車站 |
| `metro_route_stations` | 捷運營運路線車站 |
| `metro_station_timetables` | 捷運車站時刻表，結果不含版本資訊 |
| `railway_lines` | 臺鐵路線 |
| `railway_networks` | 臺鐵路網 |
| `railway_daily_timetables` | 臺鐵當日時刻表 |
| `railway_daily_trains` | 臺鐵當日車次 |
| `railway_recurring_timetables` | 臺鐵定期時刻表 |
| `railway_recurring_trains` | 臺鐵定期車次 |
| `railway_fares` | 臺鐵票價 |
| `railway_stations` | 臺鐵車站 |
| `railway_line_stations` | 臺鐵路線車站 |
| `railway_train_types` | 臺鐵車種 |
| `railway_shapes` | 臺鐵路線線型 |
| `high_speed_daily_timetables` | 高鐵當日時刻表 |
| `high_speed_daily_trains` | 高鐵當日車次 |
| `high_speed_recurring_timetables` | 高鐵定期時刻表 |
| `high_speed_fares` | 高鐵票價 |
| `high_speed_stations` | 高鐵車站 |
| `high_speed_exits` | 高鐵車站出入口 |
| `high_speed_shapes` | 高鐵路線線型 |

## 交通事故

```python
for accident in client.historical.accidents("A1", "TPE", 2025):
    print(accident.happened_at, accident.site, accident.deaths)

for intersection in client.historical.accident_ranking("TPE", 2025):
    print(intersection.rank, intersection.road)
```

當事人資料以 `accident_parties` 取得，各代碼的意義以 `accident_codes` 取得。

所有參數與欄位見[歷史資料 API](/reference/historical)。