Skip to main content

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

Metadata

Release files for py12306 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 py12306 0.1.1
File Size Uploaded Provenance Actions
py12306-0.1.1.tar.gz 15.0 kB Without provenance Details for py12306-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 30.5 kB

Release files / py12306-0.1.1.tar.gz

Download URL py12306-0.1.1.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ad6ffb693f92788793caf8574546f329d118f2dd65ff379279427b426cf6337f
BLAKE2b-256 checksum
How to use checksums
7eedf011fac384707b8aaf7b511475957c7013201b9489e86436fc007fa8a8b8
Upload date
Uploaded using Trusted Publishing?
What is 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}

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

Download URL py12306-0.1.1-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ec8aedcd790c3ee6fb78cea3312112c941327f134e5f4debed7160f83383e15
BLAKE2b-256 checksum
How to use checksums
aa05b299efbdf7e9274d54333091ae9c310d8277b722da7d48b5bfa7f1fca2a8
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for py12306 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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