Access public transport information in hamburg, germany.
Project description
HVV Geofox Python Library
About
This library is a Python wrapper for the Geofox API, which provides public transport data for Hamburg, Germany (HVV). It uses aiohttp for async HTTP requests and returns fully typed Pydantic models for all responses.
How to get API credentials
Apply for credentials via the HVV website. See their official guide here (German only). After signing and returning the contract, you will receive your credentials within about a week.
Documentation
This library mirrors the data types and parameters defined in the GTI documentation. All request and response types are Pydantic models generated from the GTI OpenAPI spec.
Installation
Install from PyPI:
pip install pygti
Requirements: Python 3.12+, aiohttp, pydantic
Usage
Minimal example
import asyncio
import aiohttp
from pygti.auth import Auth
from pygti.gti import GTI
from pygti.models import InitRequest
async def main():
async with aiohttp.ClientSession() as session:
auth = Auth(session, "GTI_USERNAME", "GTI_PASSWORD")
gti = GTI(auth)
ir = await gti.init(InitRequest())
print(ir.version, ir.buildDate)
asyncio.run(main())
Departure list
import asyncio
import aiohttp
from pygti.auth import Auth
from pygti.gti import GTI
from pygti.models import DLRequest, GTITime, SDName, SDNameType
async def main():
async with aiohttp.ClientSession() as session:
auth = Auth(session, "GTI_USERNAME", "GTI_PASSWORD")
gti = GTI(auth)
response = await gti.departureList(
DLRequest(
station=SDName(
name="Wartenau",
id="Master:10901",
type=SDNameType.STATION,
),
time=GTITime(date="heute", time="jetzt"),
maxList=5,
maxTimeOffset=200,
useRealtime=True,
)
)
for dep in response.departures:
print(f"{dep.line.name:5} -> {dep.line.direction} in {dep.timeOffset} min")
asyncio.run(main())
Connection search
from pygti.models import GRRequest, SDName, SDNameType, GTITime
response = await gti.getRoute(
GRRequest(
start=SDName(name="Hamburg Hbf", type=SDNameType.STATION),
dest=SDName(name="Hamburg Airport", type=SDNameType.STATION),
time=GTITime(date="heute", time="jetzt"),
)
)
for schedule in response.schedules:
print(schedule.plannedDepartureTime, "->", schedule.plannedArrivalTime)
Error handling
from pygti import GTIError
try:
response = await gti.departureList(...)
except GTIError as e:
print(f"API error: {e.return_code} — {e.error_text}")
Options
# Custom host (e.g. test environment)
auth = Auth(session, username, password, host="api-test.geofox.de")
# English responses
gti = GTI(auth, language="en")
API reference
All methods on GTI are async and accept a typed request model, returning a typed response model.
All request and response models are importable from pygti.models. See the GTI documentation for detailed parameter descriptions.
Migrating from a pre-V1 version
See MIGRATION_TO_V1.md for a full list of breaking changes and how to update your code.
Developing
The models in pygti/models.py are generated from the GTI OpenAPI spec. To regenerate them:
uv sync
python scripts/codegen.py
Contributions are welcome!
If you want to contribute, please read the Contribution guidelines.
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 pygti-1.0.0.tar.gz.
File metadata
- Download URL: pygti-1.0.0.tar.gz
- Upload date:
- Size: 80.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e600bf84bbb3b199cfbc43ca4f72f78377769aaacb9f87b038cd0f6050ade6c
|
|
| MD5 |
a4cb03cf2c63dbb2a7ba12e81eb94dff
|
|
| BLAKE2b-256 |
49d8de3c104e11e5400be4268d4d51b9c5a54a935de50fd9665d20d12d2613db
|
Provenance
The following attestation bundles were made for pygti-1.0.0.tar.gz:
Publisher:
publish.yml on vigonotion/pygti
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygti-1.0.0.tar.gz -
Subject digest:
4e600bf84bbb3b199cfbc43ca4f72f78377769aaacb9f87b038cd0f6050ade6c - Sigstore transparency entry: 1672577973
- Sigstore integration time:
-
Permalink:
vigonotion/pygti@c17b1406ab4f5d59f234400cd247027d3002b2b1 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vigonotion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c17b1406ab4f5d59f234400cd247027d3002b2b1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pygti-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pygti-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f583fba40af402dc0d801b74e38aa2a08dfdaf3b5c132598a1a68f3031f2393
|
|
| MD5 |
1f91aaa79a03182c718528d0cbe3c481
|
|
| BLAKE2b-256 |
b1fe92feb6d8cea7ab67071d304e7aa1aacf503520d94a67e7085df10f639770
|
Provenance
The following attestation bundles were made for pygti-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on vigonotion/pygti
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygti-1.0.0-py3-none-any.whl -
Subject digest:
4f583fba40af402dc0d801b74e38aa2a08dfdaf3b5c132598a1a68f3031f2393 - Sigstore transparency entry: 1672578027
- Sigstore integration time:
-
Permalink:
vigonotion/pygti@c17b1406ab4f5d59f234400cd247027d3002b2b1 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/vigonotion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c17b1406ab4f5d59f234400cd247027d3002b2b1 -
Trigger Event:
release
-
Statement type: