trenitalia-api
Python client (sync + async) for the public ViaggiaTreno (Trenitalia) API.
Install
uv add git+ssh://git@git.homelab.devncode.it:2222/marco/trenitalia-api.git
Example
from trenitalia_api import Client
with Client() as c:
r = c.trains.search(9642)
status = c.trains.status(r.train_id, r.train_number, r.timestamp)
print(f"{status.origin} → {status.destination} ({status.delay} min)")
Same interface, async:
import asyncio
from trenitalia_api import AsyncClient
async def main():
async with AsyncClient() as c:
r = await c.trains.search(9642)
status = await c.trains.status(r.train_id, r.train_number, r.timestamp)
print(status)
asyncio.run(main())
Service alerts: client.alerts.list().
Look up stations and check live timetables:
with Client() as c:
matches = c.stations.autocomplete("moncalieri")
detail = c.stations.detail(matches[0].station_id)
for t in c.stations.departures(detail.station_id):
print(t.scheduled_departure, t.train_label, "→", t.destination)
Errors (network, 404, malformed payload) raise an exception. They all inherit from TrenitaliaError. See trenitalia_api/exceptions.py.
Test
uv run pytest # unit, 80% coverage gate
uv run pytest tests/integration -m integration # against the live API (optional)
Metadata
Release files for trenitalia-api 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| trenitalia_api-0.2.0.tar.gz | 79.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| trenitalia_api-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 94.5 kB
Release files / trenitalia_api-0.2.0.tar.gz
| Download URL | trenitalia_api-0.2.0.tar.gz |
|---|---|
| Size | 79.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e698c5951ff396698f34ec6977181820a25e0c1ed8d20797b1a4a1f86e0b5db
|
|
BLAKE2b-256 checksum How to use checksums |
314517e78fe3a5cd53bd143d7b2ba51dea1d16ca44fdc7ebaf3ae085d8f9f623
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency logRelease files / trenitalia_api-0.2.0-py3-none-any.whl
| Download URL | trenitalia_api-0.2.0-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f00366a3ef0b05920904f6291f61d8da6c79d20ce5c81999ab816578756f6c33
|
|
BLAKE2b-256 checksum How to use checksums |
1f4710bb6e591bb7666366a99b3d7d79b80b865b54d0af336d5b442079d643ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2026.
Transparency log