Metadata-Version: 2.4
Name: trenitalia-api
Version: 0.2.0
Summary: Async + sync Python client for the public ViaggiaTreno (Trenitalia) API.
Project-URL: Homepage, https://github.com/marcocot/trenitalia-api
Project-URL: Repository, https://github.com/marcocot/trenitalia-api
Project-URL: Issues, https://github.com/marcocot/trenitalia-api/issues
Author: Marco Cotrufo
License: MIT License
        
        Copyright (c) 2026 Marco Cotrufo
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: italy,trains,trenitalia,viaggiatreno
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.7
Requires-Dist: selectolax>=0.3.21
Description-Content-Type: text/markdown

# trenitalia-api

Python client (sync + async) for the public ViaggiaTreno (Trenitalia) API.

## Install

```bash
uv add git+ssh://git@git.homelab.devncode.it:2222/marco/trenitalia-api.git
```

## Example

```python
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:

```python
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:

```python
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

```bash
uv run pytest                                    # unit, 80% coverage gate
uv run pytest tests/integration -m integration   # against the live API (optional)
```
