Trenitalia APItrenitalia.com ↗
Access real-time Trenitalia train status, delays, station departure/arrival boards, ticket search, and traffic alerts via 8 structured API endpoints.
What is the Trenitalia API?
The Trenitalia API exposes 8 endpoints covering live train status, station boards, ticket availability, and network alerts across Italy's rail network. Use get_train_status to retrieve a train's current delay in minutes, its full stop itinerary, and origin/destination data, or call search_trains to query fares and schedules between any two stations by their 9-digit location IDs.
curl -X GET 'https://api.parse.bot/scraper/0bea8d74-c4a1-467d-8b53-8e860a100320/get_station_autocomplete?query=Roma' \ -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 trenitalia-com-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.
"""Trenitalia SDK — search trains, check live status, browse station boards."""
from parse_apis.trenitalia_api import Trenitalia, TrainNotFound
client = Trenitalia()
# Search stations for ticket booking (returns 9-digit IDs for search_trains)
roma = client.locations.search(query="Roma", limit=3).first()
print(f"Location: {roma.name} (ID: {roma.id}, multistation: {roma.multistation})")
# Get real-time station board — departures from Roma Termini
station = client.stations.search(query="Roma", limit=1).first()
for dep in station.departures(limit=5):
print(f" Train {dep.numero_treno} to {dep.destinazione} at {dep.comp_orario_partenza} (delay: {dep.ritardo} min)")
# Check live status of a specific train
try:
status = client.trainstatuses.get(train_number="9611")
print(f"Train {status.numero_treno}: {status.origine} → {status.destinazione}, delay {status.ritardo} min")
except TrainNotFound as exc:
print(f"Train not found: {exc.train_number}")
# Browse current traffic alerts
for alert in client.alerts.list(limit=2):
print(f"Alert: {alert.title} ({alert.date})")
# Search tickets Roma → Milano
result = client.trainsearches.search(origin_id="830008409", destination_id="830001700")
for sol in result.solutions[:3]:
print(f" {sol.origin} → {sol.destination}: departs {sol.departure_time}, duration {sol.duration}")
print("exercised: locations.search / stations.search / station.departures / trainstatuses.get / alerts.list / trainsearches.search")
Autocomplete station name search for real-time data (ViaggiaTreno). Returns stations matching the given prefix with their IDs for use in departure/arrival board and train status endpoints. Each station has a short ID (e.g. 'S08409') usable with get_station_departures and get_station_arrivals.
| Param | Type | Description |
|---|---|---|
| queryrequired | string | Station name prefix to search (e.g. 'Roma', 'Milano', 'Napoli') |
{
"type": "object",
"fields": {
"data": "array of station objects with id, label, nomeBreve, nomeLungo",
"status": "string, always 'success'"
}
}About the Trenitalia API
Station and Train Lookup
Two autocomplete endpoints handle identifier resolution before you query live data. get_station_autocomplete accepts a station name prefix and returns objects with id, nomeBreve, and nomeLungo fields — the id values (e.g. S08409 for Roma Termini) feed get_station_departures and get_station_arrivals. For ticket searches you need a different ID format: get_location_search returns 9-digit numeric IDs such as 830008409, along with displayName, multistation, and centroidId, which are required by search_trains. get_train_autocomplete resolves a train number to an origin_id and timestamp in milliseconds, both needed for precise status lookups.
Real-Time Train and Station Data
get_train_status returns a full picture of a running train: ritardo (delay in minutes), origine, destinazione, numeroTreno, and a fermate array listing each stop with its own timing and status. If you omit origin_id and timestamp, the endpoint auto-resolves them using the train number. Station boards are split into two endpoints: get_station_departures returns compOrarioPartenza, destinazione, ritardo, and categoriaDescrizione per train; get_station_arrivals mirrors that structure with origine and compOrarioArrivo.
Ticket Search and Traffic Alerts
search_trains takes an origin_id, destination_id, optional departure_time in ISO format (YYYY-MM-DDTHH:MM:SS.mmm), and optional passenger counts for adults and children. The response includes a searchId, cartId, and a solutions array with pricing, duration, and available service classes per train. get_traffic_info requires no parameters and returns current network disruption alerts with title, date, and content fields in Italian, sourced from the Infotraffico service.
The Trenitalia API is a managed, monitored endpoint for trenitalia.com — not a raw scraper you maintain. Every endpoint is automatically health-checked on a schedule, and when trenitalia.com 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 trenitalia.com 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?+
- Display a live departure board for any Italian station using
get_station_departureswith real-timeritardodelay data. - Build a train delay tracker that polls
get_train_statusforritardoandfermatestop-by-stop timing. - Integrate fare comparison into a travel app by querying
search_trainswith adult/child counts and a departure time. - Alert commuters to active service disruptions by surfacing
get_traffic_infoalerts filtered by title or date. - Resolve arbitrary station names to IDs programmatically using
get_station_autocompletebefore querying boards. - Look up whether a specific train number is currently running via
get_train_autocompletebefore fetching its status. - Power an arrival notification service by monitoring
get_station_arrivalsfor a targetorigineand expectedcompOrarioArrivo.
| 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.
Does Trenitalia offer an official developer API?+
What does `get_train_status` return, and do I always need to supply `origin_id` and `timestamp`?+
ritardo (delay in minutes), origine, destinazione, numeroTreno, and a fermate array of stops with individual timing data. Both origin_id and timestamp are optional — if you omit them, the endpoint resolves them automatically from the train number using the autocomplete lookup. Supply them explicitly when you want to target a specific scheduled departure.Does the API cover international trains or only domestic Italian routes?+
Does the API support searching trains for a past date or historical schedule data?+
get_station_departures, get_station_arrivals) return departures and arrivals around the current time and do not accept a date parameter. search_trains accepts a future departure_time. Historical schedule data and past departure boards are not currently covered. You can fork this API on Parse and revise it to add the missing historical endpoint if that surface becomes accessible.Are ticket prices returned in `search_trains` responses, and which passenger types are supported?+
solutions array in the search_trains response includes pricing alongside duration and service class details per train. Passenger counts are configurable via the adults and children integer parameters. Senior, loyalty, or regional discount fares beyond the adult/child split are not exposed as separate parameters in the current endpoint.