Skip to main content

TaiwanBus

台灣公車,全台皆可使用

前置作業

從pip下載/更新

pip install TaiwanBus -U

從儲存庫安裝

# 複製儲存庫
git clone https://github.com/AvianJay/TaiwanBus

# 進入資料夾
cd TaiwanBus

# 安裝
pip install .

更新公車資料庫

taiwanbus updatedb

用法

終端機

usage: taiwanbus [-h] [-p PROVIDER]
          {updatedb,showroute,searchroute,searchstop} ...

TaiwanBus

positional arguments:
   {updatedb,showroute,searchroute,searchstop}
       updatedb            更新公車資料庫
       showroute           顯示公車路線狀態
       searchroute         查詢路線
       searchstop          查詢站點

options:
   -h, --help            show this help message and exit
   -p PROVIDER, --provider PROVIDER
                             資料庫

Python

# 引入依賴庫
from taiwanbus.session import BusSession
from taiwanbus import api

# 更新資料庫
api.update_database()

# 地區資料庫
# 全台(無站點資料,無法查詢單一車站):twn
# 台中:tcc
# 台北:tpe
# 取得路線
bus = BusSession("304030", api.Provider.TWN)  # 綠3, 全台

# 更新資訊
bus.update()

# 取得資訊
bus.get_info()

# 取得站點
bus.get_stop(...)

# 模擬功能
bus.start_simulate()
bus.get_simulated_info()

taiwanbus.api

update_database_dir(path: str) -> bool

更新資料庫的路徑,返回資料夾是否可使用。

update_provider(provider: taiwanbus.api.Provider) -> None

更新使用的地區。

check_database_update(path: str=None) -> dict

檢查資料庫的更新,返回字典。 範例:

{
    "twn": None,  # 沒有更新
    "tcc": 442,  # 有更新,版本號為 442
    "tpe": 442
}

update_database(path: str=None, info: bool=False)

path: 路徑,若未指定將使用預先設定的。 info: 是否記錄更新到控制台

fetch_route(id: int) -> list

從資料庫取得路線,不包含線上資訊。

fetch_all_routes() -> list

從資料庫取得所有路線,不包含線上資訊。

fetch_routes_by_name(name: str) -> list

使用關鍵字搜尋路線,不包含線上資訊。

fetch_stop(id: int) -> list

只適用於 tcc 跟 tpe 資料庫 從資料庫取得站點資訊,不包含線上資訊。

fetch_stops_by_name(name: str) -> list

只適用於 tcc 跟 tpe 資料庫 使用關鍵字搜尋站點,不包含線上資訊。

fetch_paths(id: int) -> list

id 為路線 id 從資料庫取得路線的方向,不包含線上資訊。

fetch_path_by_stop(id: int) -> list

使用站點id取得路線方向資訊,不包含線上資訊。

fetch_stops_by_route(route_key: int) -> list

使用路線id取得所有站點,若使用 twn 資料庫將會線上取得站點。

fetch_stops_nearby(lat: float, lon: float, radius: int = 100) -> list

lat, lan: 座標 radius: 距離(公尺) 取得指定座標內距離的站點,不包含線上資訊。

getbus(id) -> list

線上取得路線資訊,不包含資料庫的東西。

get_complete_bus_info(route_key) -> dict

使用路線id取得整個路線的資訊,包含所有資訊。

format_bus_info(json_data: dict) -> str

將 get_complete_bus_info 返回的字典格式成可視化文字。

Termux/Discord

項目已移至AvianJay/TaiwanBus-Utils。

Credit

API by Yahoo!
(謝謝Yahoo 沒有你就不會有這個)

Metadata

Release files for TaiwanBus 0.1.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 TaiwanBus 0.1.1
File Size Uploaded
taiwanbus-0.1.1.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for TaiwanBus 0.1.1
File Interpreter ABI Platform
taiwanbus-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.5 kB

Release files / taiwanbus-0.1.1.tar.gz

Download URL taiwanbus-0.1.1.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
82d048144c4263af2b1c219f260631aa50d628d1c8987d4f5d4668e82f4443d9
BLAKE2b-256 checksum
How to use checksums
0e7d9fbda9f1b340dd3317098e14b0eb5aec370004f3ee9d3c3a8be05ac0342c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.

Transparency log

Release files / taiwanbus-0.1.1-py3-none-any.whl

Download URL taiwanbus-0.1.1-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38193c934d338809910c070070ddf926816d24212f97b2a4f82fa4d37ab79d62
BLAKE2b-256 checksum
How to use checksums
ea78542c13f1da02effaf870a9aad37d9aeb504cdc38f352997359dc6988a3bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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