Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trenitalia_api-0.2.0.tar.gz (79.7 kB view details)

Uploaded Source

Built Distribution

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

trenitalia_api-0.2.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

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

Hashes for trenitalia_api-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5e698c5951ff396698f34ec6977181820a25e0c1ed8d20797b1a4a1f86e0b5db
MD5 4650b32b84b3b15970b13d20702d6367
BLAKE2b-256 314517e78fe3a5cd53bd143d7b2ba51dea1d16ca44fdc7ebaf3ae085d8f9f623

See more details on using hashes here.

Provenance

The following attestation bundles were made for trenitalia_api-0.2.0.tar.gz:

Publisher: release.yml on marcocot/trenitalia-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for trenitalia_api-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f00366a3ef0b05920904f6291f61d8da6c79d20ce5c81999ab816578756f6c33
MD5 aec6b5b42988a295f92bac7e85a5b066
BLAKE2b-256 1f4710bb6e591bb7666366a99b3d7d79b80b865b54d0af336d5b442079d643ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for trenitalia_api-0.2.0-py3-none-any.whl:

Publisher: release.yml on marcocot/trenitalia-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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