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.0.0.tar.gz (80.5 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.0.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

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

Hashes for pygti-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4e600bf84bbb3b199cfbc43ca4f72f78377769aaacb9f87b038cd0f6050ade6c
MD5 a4cb03cf2c63dbb2a7ba12e81eb94dff
BLAKE2b-256 49d8de3c104e11e5400be4268d4d51b9c5a54a935de50fd9665d20d12d2613db

See more details on using hashes here.

Provenance

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

Hashes for pygti-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f583fba40af402dc0d801b74e38aa2a08dfdaf3b5c132598a1a68f3031f2393
MD5 1f91aaa79a03182c718528d0cbe3c481
BLAKE2b-256 b1fe92feb6d8cea7ab67071d304e7aa1aacf503520d94a67e7085df10f639770

See more details on using hashes here.

Provenance

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