Skip to main content

Access public transport information in hamburg, germany.

Project description

HVV Geofox Python Library

Release


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


Download files

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

Source Distribution

pygti-1.1.1.tar.gz (83.8 kB view details)

Uploaded Source

Built Distribution

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

pygti-1.1.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file pygti-1.1.1.tar.gz.

File metadata

  • Download URL: pygti-1.1.1.tar.gz
  • Upload date:
  • Size: 83.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pygti-1.1.1.tar.gz
Algorithm Hash digest
SHA256 646bbe5e658a8a97e02c2713d45e380effc0abd8e4e4285f41e27e0e400d04ab
MD5 d68dd3d5ae04aa468651f1aa8aed7db7
BLAKE2b-256 fcdab509ecb8830d408ef738b2dff68510917eb6181530c616da097698134f70

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygti-1.1.1.tar.gz:

Publisher: publish.yml on vigonotion/pygti

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

File details

Details for the file pygti-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: pygti-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pygti-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57a3fc048eb839bac0e200b88f9beed88cefa781c85f9475557ef067c798afee
MD5 e50c41a7ee000bdde1dbd9c83825834b
BLAKE2b-256 7b2d6d710936c9c72d1d42e8f84b03bc02bd86bf241c148c1c6aae936d1aaaa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygti-1.1.1-py3-none-any.whl:

Publisher: publish.yml on vigonotion/pygti

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