Async + sync Python client for the public ViaggiaTreno (Trenitalia) API.
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trenitalia_api-0.2.0.tar.gz.
File metadata
- Download URL: trenitalia_api-0.2.0.tar.gz
- Upload date:
- Size: 79.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e698c5951ff396698f34ec6977181820a25e0c1ed8d20797b1a4a1f86e0b5db
|
|
| MD5 |
4650b32b84b3b15970b13d20702d6367
|
|
| BLAKE2b-256 |
314517e78fe3a5cd53bd143d7b2ba51dea1d16ca44fdc7ebaf3ae085d8f9f623
|
Provenance
The following attestation bundles were made for trenitalia_api-0.2.0.tar.gz:
Publisher:
release.yml on marcocot/trenitalia-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trenitalia_api-0.2.0.tar.gz -
Subject digest:
5e698c5951ff396698f34ec6977181820a25e0c1ed8d20797b1a4a1f86e0b5db - Sigstore transparency entry: 1674183959
- Sigstore integration time:
-
Permalink:
marcocot/trenitalia-api@872afbe680cd428b85d29c0f0cbb83676f2fe2be -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/marcocot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@872afbe680cd428b85d29c0f0cbb83676f2fe2be -
Trigger Event:
push
-
Statement type:
File details
Details for the file trenitalia_api-0.2.0-py3-none-any.whl.
File metadata
- Download URL: trenitalia_api-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f00366a3ef0b05920904f6291f61d8da6c79d20ce5c81999ab816578756f6c33
|
|
| MD5 |
aec6b5b42988a295f92bac7e85a5b066
|
|
| BLAKE2b-256 |
1f4710bb6e591bb7666366a99b3d7d79b80b865b54d0af336d5b442079d643ad
|
Provenance
The following attestation bundles were made for trenitalia_api-0.2.0-py3-none-any.whl:
Publisher:
release.yml on marcocot/trenitalia-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trenitalia_api-0.2.0-py3-none-any.whl -
Subject digest:
f00366a3ef0b05920904f6291f61d8da6c79d20ce5c81999ab816578756f6c33 - Sigstore transparency entry: 1674183983
- Sigstore integration time:
-
Permalink:
marcocot/trenitalia-api@872afbe680cd428b85d29c0f0cbb83676f2fe2be -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/marcocot
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@872afbe680cd428b85d29c0f0cbb83676f2fe2be -
Trigger Event:
push
-
Statement type: