Skip to main content

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


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.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py12306-0.1.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file py12306-0.1.1.tar.gz.

File metadata

  • Download URL: py12306-0.1.1.tar.gz
  • Upload date:
  • Size: 15.0 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

Hashes for py12306-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ad6ffb693f92788793caf8574546f329d118f2dd65ff379279427b426cf6337f
MD5 f489c273d0078a5cfbf6eb88c78cec36
BLAKE2b-256 7eedf011fac384707b8aaf7b511475957c7013201b9489e86436fc007fa8a8b8

See more details on using hashes here.

File details

Details for the file py12306-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py12306-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.5 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

Hashes for py12306-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ec8aedcd790c3ee6fb78cea3312112c941327f134e5f4debed7160f83383e15
MD5 5e5c730d7195eab8f683c60769b67743
BLAKE2b-256 aa05b299efbdf7e9274d54333091ae9c310d8277b722da7d48b5bfa7f1fca2a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page