Skip to main content

Railway stations and train routes API client — trainfyi.com

Project description

trainfyi

PyPI version Python License: MIT Zero Dependencies

Python API client for railway data. Look up train stations worldwide, explore high-speed rail networks, query track gauge types, and retrieve railway operator information — all from TrainFYI, a railway reference platform covering passenger rail systems across continents.

TrainFYI catalogs railway stations with coordinates and operator associations, high-speed rail lines (Shinkansen, TGV, ICE, KTX), track gauge standards, signaling systems, and rolling stock — used by transit-tech developers, rail enthusiasts, and transportation analytics platforms.

Explore railways at trainfyi.com — browse by country, search stations, and explore rail networks.

trainfyi demo — railway station lookup, high-speed rail data, and route information in Python

Table of Contents

Install

pip install trainfyi                # Core (zero deps)
pip install "trainfyi[cli]"         # + Command-line interface
pip install "trainfyi[mcp]"         # + MCP server for AI assistants
pip install "trainfyi[api]"         # + HTTP client for trainfyi.com API
pip install "trainfyi[all]"         # Everything

Quick Start

from trainfyi.api import TrainFYI

with TrainFYI() as api:
    # Look up a railway station
    station = api.get_station("tokyo-station")
    print(station["name"])          # Tokyo Station
    print(station["country"])       # Japan
    print(station["operator"])      # JR East
    print(station["lines"])         # Shinkansen, Chuo, Yamanote...

    # List stations by country
    stations = api.list_stations(country="france")
    for s in stations:
        print(f"{s['name']}{s['city']}")

    # Search railway data
    results = api.search("shinkansen")

What You Can Do

High-Speed Rail Networks

High-speed rail (HSR) operates at speeds above 250 km/h on dedicated tracks. Japan pioneered the concept with the Shinkansen (1964), followed by France's TGV (1981). Today, China operates the world's largest HSR network at over 42,000 km, while Europe's network connects 10+ countries.

System Country Max Speed Network Length Opened
Shinkansen Japan 320 km/h 3,000+ km 1964
TGV France 320 km/h 2,800+ km 1981
ICE Germany 300 km/h 1,600+ km 1991
AVE Spain 310 km/h 3,600+ km 1992
KTX South Korea 305 km/h 600+ km 2004
CRH China 350 km/h 42,000+ km 2007
Frecciarossa Italy 300 km/h 1,000+ km 2009
from trainfyi.api import TrainFYI

with TrainFYI() as api:
    # Search for high-speed rail lines
    results = api.search("shinkansen")
    for r in results:
        print(f"{r['name']}{r.get('max_speed', 'N/A')} km/h")

    # Browse networks by country
    networks = api.list_networks(country="japan")

Learn more: Rail Networks · Glossary

Track Gauge Types

Track gauge — the distance between the inner faces of the rails — varies worldwide and determines rolling stock compatibility. Standard gauge (1,435 mm) is used by 60% of the world's railways, but significant networks operate on broad gauge (Russia, India, Iberia) or narrow gauge (Japan conventional, Southeast Asia).

Gauge Width Where Used
Standard 1,435 mm Europe, China, US, Japan HSR, Korea
Russian/Finnish 1,520/1,524 mm Russia, CIS, Finland, Baltic states
Indian 1,676 mm India, Pakistan, Argentina
Iberian 1,668 mm Spain, Portugal (conventional)
Cape 1,067 mm Japan (conventional), South Africa, Australia
Meter 1,000 mm Southeast Asia, Switzerland, Brazil
Narrow 762 mm Heritage railways, mining
from trainfyi.api import TrainFYI

with TrainFYI() as api:
    # Look up gauge information by country
    country = api.get_country("japan")
    print(f"Gauges: {country.get('track_gauges')}")
    # Standard (Shinkansen), Cape gauge (conventional)

Learn more: Track Gauges · Glossary

Railway Stations

Railway stations range from major termini handling hundreds of thousands of daily passengers (Shinjuku: 3.5M/day, the world's busiest) to rural halts with a single platform. Station architecture often reflects the era of construction — grand 19th-century termini, modernist mid-century designs, and contemporary glass-and-steel structures.

from trainfyi.api import TrainFYI

with TrainFYI() as api:
    # Get station details
    station = api.get_station("gare-du-nord")
    print(f"{station['name']}, {station['city']}")
    print(f"Operator: {station['operator']}")
    print(f"Lines: {station.get('lines', [])}")

    # List all stations in a country
    stations = api.list_stations(country="germany")
    print(f"{len(stations)} stations in Germany")

Learn more: Station Directory · Guides

Signaling Systems

Railway signaling ensures safe train separation and routing. Modern systems range from traditional fixed-block signaling (trackside signals) to ERTMS/ETCS (European Train Control System) and CBTC (Communications-Based Train Control) for metros. Positive Train Control (PTC) is mandated in the United States.

System Type Where Used
ERTMS/ETCS Moving block, cab signaling EU interoperability standard
PTC Overlay GPS/radio United States (mandated)
ATC/ATS Cab signaling Japan (Shinkansen)
CBTC Communications-based Metro systems worldwide
TVM Track-to-train transmission France (TGV)
from trainfyi.api import TrainFYI

with TrainFYI() as api:
    # Search signaling systems
    results = api.search("ETCS")
    for r in results:
        print(r["name"])

Learn more: Railway Technology · API Documentation

Command-Line Interface

pip install "trainfyi[cli]"

trainfyi station tokyo-station               # Station details
trainfyi search "gare du nord"               # Search stations
trainfyi country japan                       # All stations in Japan
trainfyi countries                           # List all countries

MCP Server (Claude, Cursor, Windsurf)

pip install "trainfyi[mcp]"
{
    "mcpServers": {
        "trainfyi": {
            "command": "uvx",
            "args": ["--from", "trainfyi[mcp]", "python", "-m", "trainfyi.mcp_server"]
        }
    }
}

REST API Client

from trainfyi.api import TrainFYI

with TrainFYI() as api:
    station = api.get_station("tokyo-station")       # GET /api/v1/stations/tokyo-station/
    stations = api.list_stations(country="france")    # GET /api/v1/stations/?country=france
    countries = api.list_countries()                  # GET /api/v1/countries/
    results = api.search("eurostar")                 # GET /api/v1/search/?q=eurostar

Example

curl -s "https://trainfyi.com/api/v1/stations/tokyo-station/"
{
    "slug": "tokyo-station",
    "name": "Tokyo Station",
    "city": "Tokyo",
    "country": "Japan",
    "operator": "JR East"
}

Full API documentation at trainfyi.com/developers/.

API Reference

Function Description
api.get_station(slug) Station details (location, operator, lines)
api.list_stations(country) List stations, optionally by country
api.list_countries() All countries with station counts
api.get_country(slug) Country details with station list
api.search(query) Search stations, networks, and operators

Learn More About Railways

Also Available

Platform Install Link
npm npm install trainfyi npm
MCP uvx --from "trainfyi[mcp]" python -m trainfyi.mcp_server Config

Transport FYI Family

Part of the FYIPedia open-source developer tools ecosystem — airports, airlines, aircraft, and railways.

Package PyPI npm Description
airportfyi PyPI npm 4,500+ airports, IATA/ICAO codes, routes — airportfyi.com
airlinefyi PyPI npm Airlines, fleets, alliances, routes — airlinefyi.com
planefyi PyPI npm Aircraft models, specifications, manufacturers — planefyi.com
trainfyi PyPI npm Railway stations, train routes, rail networks — trainfyi.com

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

trainfyi-0.1.1.tar.gz (165.3 kB view details)

Uploaded Source

Built Distribution

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

trainfyi-0.1.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trainfyi-0.1.1.tar.gz
  • Upload date:
  • Size: 165.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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 trainfyi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a7e8513ea1169c5d5a5b7090ebebb7861138bb47b59e8d020a48bf791a3de73b
MD5 d834b6020233b3d5b2ae6083e7059a49
BLAKE2b-256 cc53cc9baecb73962cb5750515b6c202ff402b585e303c16e7bdc1bb5dbb9d99

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trainfyi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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 trainfyi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 06d48c22c20ea20ec1887a106bde63d4fb1900113abd08437192e718745bb80b
MD5 6d0289a14b17b633b5f14789071bd36d
BLAKE2b-256 093aa85ad886027b401ab7b7079fc896335d5f96a1bba2feb37a4622c4f9f087

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