Trainline APItrainline.eu ↗
Search Trainline stations by name and find train journeys across the UK and Europe. Returns URNs, schedules, duration, distance, and CO2 data.
What is the Trainline API?
The Trainline EU API provides 2 endpoints for discovering train stations and searching available journeys across the UK and Europe. Use search_locations to resolve station names to URNs, then pass those URNs to search_journeys to retrieve journey schedules with departure and arrival times, total duration, distance in kilometres, and CO2 emissions per journey.
curl -X GET 'https://api.parse.bot/scraper/447b13bc-e3c7-4dca-a183-dbdaa6edee8a/search_locations?query=London' \ -H 'X-API-Key: $PARSE_API_KEY'
Typed, relational, agent-ready
A generated client with real types, enums, and the links between objects — the structure a flat JSON response can't carry. Autocompletes in your editor and reads cleanly to coding agents.
- Fully typed · autocompletes
- Objects link to objects
- Typed errors & pagination
Typed Python client. Set up the SDK in your uv project, then pull this API’s typed client:
uv add parse-sdk uv run parse init uv run parse add --marketplace trainline-eu-api
uv run parse add --marketplace pulls a pinned snapshot of this canonical API — it won’t change underneath you. To customize it, subscribe and swap to your own copy.
"""Trainline API — search stations and find train journeys between them."""
from parse_apis.trainline_api import Trainline, StationNotFound
client = Trainline()
# Search for stations by name — limit caps total items fetched
for station in client.stations.search(query="Manchester", limit=5):
print(station.name, station.urn, station.country)
# Take one station, then search journeys from London to that destination
destination = client.stations.search(query="Manchester", limit=1).first()
if destination:
for journey in client.journeys.search(
origin="urn:trainline:generic:loc:182gb",
destination=destination.urn,
departure_date="2026-06-20",
limit=3,
):
print(journey.departure_time, journey.arrival_time, journey.duration, journey.co2_grams)
# Typed error handling — catch when a station search yields nothing useful
try:
result = client.stations.search(query="Xyzzyville", limit=1).first()
print(result.name if result else "No station found")
except StationNotFound as exc:
print(f"Station not found: {exc}")
print("exercised: stations.search / journeys.search / StationNotFound catch")
Search for train station locations by name. Returns station URNs, coordinates, and metadata. Each station has a URN that uniquely identifies it and can be used as origin or destination in search_journeys. Results include both individual stations and station groups (e.g. 'London' encompasses multiple terminals). Partial name matching is supported.
| Param | Type | Description |
|---|---|---|
| queryrequired | string | Station name or partial name to search for (e.g. 'London', 'Manchester', 'Paris'). |
{
"type": "object",
"fields": {
"locations": "array of station objects with name, urn, country, type, timezone, latitude, longitude"
},
"sample": {
"data": {
"locations": [
{
"urn": "urn:trainline:generic:loc:182gb",
"name": "London",
"type": "stationGroup",
"country": "GB",
"latitude": null,
"timezone": "Europe/London",
"longitude": null
},
{
"urn": "urn:trainline:generic:loc:EUS1444gb",
"name": "London Euston",
"type": "station",
"country": "GB",
"latitude": 51.5284,
"timezone": "Europe/London",
"longitude": -0.1346
}
]
},
"status": "success"
}
}About the Trainline API
Station Search
The search_locations endpoint accepts a query string — a full or partial station name such as London, Manchester, or Paris — and returns an array of matching station objects. Each object includes a name, a urn (e.g. urn:trainline:generic:loc:182gb), country, type, timezone, and geographic coordinates (latitude, longitude). The URN is the key identifier used as origin or destination in journey searches.
Journey Search
The search_journeys endpoint accepts origin and destination as station URNs obtained from search_locations. An optional departure_date parameter accepts ISO 8601 format: either YYYY-MM-DD (which defaults departure time to 09:00) or a full datetime string YYYY-MM-DDTHH:MM. The response includes a total count and a journeys array. Each journey object carries id, departure_time, arrival_time, duration, direction, distance_km, co2_grams, and num_legs.
Coverage and Data Shape
Station coverage spans UK and European networks as indexed on Trainline.com. The CO2 emissions field (co2_grams) makes the API useful for comparing journeys on environmental impact alongside schedule and distance. The num_legs field indicates how many segments a journey involves, letting you distinguish direct services from those requiring changes.
The Trainline API is a managed, monitored endpoint for trainline.eu — not a raw scraper you maintain. Every endpoint is automatically health-checked on a schedule, and when trainline.eu changes and a check fails, the API is automatically queued for repair and re-verified. It is built to keep working as the site underneath it changes.
This isn't an official trainline.eu API — it's an independent, maintained REST wrapper over public data. Where the source has no official API (or only a limited one), Parse gives you a stable contract over a source that never promised one, and keeps it current. Need a new endpoint or field? You can revise it yourself in plain English and the agent rebuilds it against the live site in minutes — contributing the change back to the shared API is free.
Will this API break when the source site changes?+
Is this an official API from the source site?+
Can I fix or extend this API myself if I need a new endpoint or field?+
What happens if I call an endpoint that has an issue?+
- Build a train journey planner that compares travel times between UK cities using departure and arrival fields
- Display CO2 emissions per route to help users choose lower-carbon journeys
- Resolve station names to URNs for use in downstream booking or scheduling workflows
- Calculate travel distance between European cities using the distance_km field
- Filter multi-leg vs direct journeys by inspecting the num_legs field
- Populate an autocomplete station selector using search_locations with partial name queries
- Aggregate journey duration data across multiple departure times to find the fastest available service
| Tier | Price | Credits/month | Rate limit |
|---|---|---|---|
| Free | $0/mo | 100 | 5 req/min |
| Hobby | $30/mo | 1,000 | 20 req/min |
| Developer | $100/mo | 5,000 | 100 req/min |
One credit = one API call regardless of which marketplace API you call. Exceeding the rate limit returns a 429 response. Authenticate with the X-API-Key header.