Metadata-Version: 2.4
Name: bahnapi
Version: 0.1.0
Summary: Convenience wrapper for Deutsche Bahn Timetables API.
Author: Sebastian Speetzen
License: MIT License
        
        Copyright (c) 2025 Sebastian Speetzen
        
        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.
        
Project-URL: Homepage, https://github.com/speetzial/bahnapi
Keywords: bahn,deutschebahn,train,timetable,api
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31.0
Provides-Extra: dev
Requires-Dist: python-dotenv>=1.0.0; extra == "dev"
Dynamic: license-file

## Installation

```bash
pip install bahnapi
```

Python 3.9 or newer is required. The only runtime dependency is `requests>=2.31.0`.

## Configuration

The Deutsche Bahn API requires credentials. Configure BahnAPI in one of two ways.

### Programmatic configuration

```python
import bahnapi

bahnapi.configure(
    client_id="YOUR_CLIENT_ID",
    api_key="YOUR_API_KEY",
    timeout=15,  # optional, seconds
)
```

## Quick Start

```python
import datetime as dt
import bahnapi

bahnapi.configure("YOUR_CLIENT_ID", "YOUR_API_KEY")

now = dt.datetime.now(dt.UTC)
departures = bahnapi.get_departures(
    station_id="8011160",  # Berlin Hbf
    start_time=now,
    end_time=now + dt.timedelta(hours=1),
    include_recent_changes=True,  # also merge /rchg
)

for dep in departures[:3]:
    print(
        dep["departure_planned"],
        dep["departure_actual"],
        dep["destination_name"],
        dep["delay_minutes"],
    )
```

Each entry is intentionally compact:

- `stop_id`, `station_eva`
- `departure_planned`, `departure_actual`, `delay_minutes`
- `platform_planned`, `platform_actual`
- `destination_name`, `train_category`, `train_number`, `operator`
- optional `messages` list (only essential fields)

## Station Search

```python
from bahnapi import search_stations

matches = search_stations("Berlin Hbf", limit=5)
if matches:
    print(matches[0]["eva"])
```

Use `bahnapi.stations.resolve_station_eva(pattern)` to enforce a single match; it raises `StationLookupError` when ambiguous or missing.

## API Overview

```python
bahnapi.configure(client_id, api_key, timeout=10)
bahnapi.get_departures(station_id, start_time, end_time, include_recent_changes=False)
bahnapi.search_stations(pattern, limit=None)
bahnapi.stations.resolve_station_eva(pattern)
```

Exceptions live in `bahnapi.exceptions`:

- `BahnAPIError` (base class)
- `AuthenticationError`
- `RateLimitError`
- `StationLookupError`

## License

Released under the MIT License (see `LICENSE`).

## Acknowledgements

This project is unaffiliated with Deutsche Bahn. It simply wraps the official Timetables API provided via the DB API Marketplace. Always consult the official documentation for rate limits and conditions.*** End Patch
