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.0.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.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pygti-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 eed171500cdae83baa9f3baf373ed81818e47d035bec0cd38f4340c24a9f49d3
MD5 b7f61c092e7c1a295f9dd3c02b82d6bc
BLAKE2b-256 d11e337c15a3d65ae9a885096930db7a80b1c093cfb7b2b6affdca2bda122ecf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygti-1.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: pygti-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 224f68e95044b05799ccc690915364a85bcc307f73e3429350a8677e95c39965
MD5 bbf00d4905dfd8765a1615d3744deea4
BLAKE2b-256 549182b01d3e794036bbab500d3475dedca7c5c4af4db5f015f56aa2691d7ef6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygti-1.1.0-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