China Railway (12306) API client for querying stations, trains, tickets, and transfers
Project description
py12306
Python client for China Railway (12306) — query stations, trains, tickets, and transfers.
Install
pip install py12306
CLI
# Ticket search
uvx py12306 tickets --date 2026-01-25 --from 北京南 --to 上海虹桥 \
--trains G --sort duration --limit 5
# Transfer search
uvx py12306 transfers --date 2026-01-25 --from 成都 --to 杭州 \
--trains G --limit 3
# Train stops
uvx py12306 stops G1 --date 2026-01-25
# Station lookup
uvx py12306 stations 北京
Options
tickets
| Option | Description |
|---|---|
--date |
Travel date (YYYY-MM-DD) |
--from/--to |
Station or city name |
--trains |
Filter: G/D/C/Z/T/K |
--depart-after/--depart-before |
Hour range (0-23) |
--sort |
depart, arrive, duration |
--limit |
Max results |
transfers
| Option | Description |
|---|---|
--date |
Travel date (YYYY-MM-DD) |
--from/--to |
Station or city name |
--via |
Transfer station (optional, auto-detected) |
--trains |
Filter: G/D/C/Z/T/K |
--min-wait/--max-wait |
Transfer time in minutes |
--sort |
duration, depart, arrive |
--limit |
Max results |
Python API
from py12306 import (
load_stations,
get_station_by_name,
get_stations_in_city,
get_train_stops,
get_tickets,
get_transfers,
)
# Station lookup
station = get_station_by_name("北京南")
stations = get_stations_in_city("北京")
# Train stops
train = get_train_stops(train="G1", date="2026-01-25")
for stop in train.stops:
print(f"{stop.station} {stop.arrive}-{stop.depart}")
# Tickets
tickets = get_tickets(
date="2026-01-25",
src="VNP",
dst="AOH",
trains="G",
sort="duration",
limit=5,
)
# Transfers
transfers = get_transfers(
date="2026-01-25",
src="ICW",
dst="HGH",
trains="G",
limit=5,
)
Train Types
| Code | Type |
|---|---|
| G | 高铁 (High-speed, 300-350 km/h) |
| D | 动车 (EMU, 200-250 km/h) |
| C | 城际 (Intercity) |
| Z | 直达 (Direct express) |
| T | 特快 (Express) |
| K | 快速 (Fast) |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py12306-0.1.0.tar.gz
(14.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
py12306-0.1.0-py3-none-any.whl
(15.4 kB
view details)
File details
Details for the file py12306-0.1.0.tar.gz.
File metadata
- Download URL: py12306-0.1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60c8044051f5d12cf9d18d3a0065c87b19f0b9f930027bccb9d162a4481cc759
|
|
| MD5 |
114d5f97c17073149a21d443a0450d2b
|
|
| BLAKE2b-256 |
774655f686720567dce8dc7d952768a4c20b9de336b061a2a081f81a694a4c68
|
File details
Details for the file py12306-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py12306-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a1f3048c26f3d6efa60981c245805bda9c2fcf08ab92a19459f7cf678bad56c
|
|
| MD5 |
99a44ea5794c66a4385a7e35f87d5bf3
|
|
| BLAKE2b-256 |
034626e4d04ed3cf0779791d0b3ed6e3dd39cbb3b9dd23eabbbf6015156cb52a
|