Skip to main content

publictransport

A Python client for public transport APIs. It uses a shared model for stops, departures and trips that covers several server types, so an application can query any supported network the same way. It supports servers that speak EFA (used by many German transport associations), MOTIS (the routing engine behind Transitous), TRIAS 1.2, OJP 1.0, HAFAS mgate (the interface behind many operators' apps) and OpenTripPlanner 2 with its Transmodel API.

The package wraps the Rust library of the same name. The Rust code builds the requests and parses the answers, and httpx sends them. Install it with uv add publictransport or pip install publictransport; there are wheels for Linux (glibc), macOS and Windows on x86-64, and for the first two on ARM.

from publictransport import BundledNetwork, Client, LocationKind

vvo = BundledNetwork.VVO_EFA.network()

with Client(user_agent="my-app/1.0 (+https://example.org)") as client:
    stops = client.locations(vvo, "Hauptbahnhof", kinds=[LocationKind.STOP])
    for departure in client.departures(vvo, stops[0], limit=10):
        # The time on the clocks at the stop, where its time zone is known.
        time = departure.stop.local_time(departure.scheduled_time)
        print(
            f"{time:%H:%M}" if time else "?", departure.line.name, departure.direction
        )

    found = client.trips(vvo, stops[0], stops[1])
    more = client.trips(vvo, stops[0], stops[1], page=found.later)

The examples have a short program for each kind of request.

AsyncClient has the same methods as coroutines. A stop or a place is a Location from a search, a departure or a trip, or an ID as text; a place in trips can be a Coordinate too. A location that another network returned works as well: for a trip always if it has a coordinate, for departures where the asked network can name the stop, which EFA, TRIAS and OJP can for stops with a global ID. Each method also takes a query object (LocationQuery, DeparturesQuery, TripsQuery) in place of the plain values, which is what the Rust library works with.

BundledNetwork names the networks that ship with the package. Registry.bundled() holds them all, for a list to choose from: get("vvo-efa") finds one by its ID as text, and covering(Coordinate(...)) lists the networks for a position, each with the tier of its coverage there. A Network can also be written by hand, as Network(id=..., name=..., endpoint=..., protocol=Protocol.EFA, timezone="Europe/Berlin"), and network_from_json(id, json) reads further ones from entries in the format of transport-apis.

Times are timezone-aware datetime objects in UTC. Location.local_time(time) gives one as the clocks at that location show it, with the UTC offset that holds there at that time, or None where no time zone is known for it. It is for showing a time; calculate with the UTC values. A time in a query has to be timezone-aware too, in any zone. An EFA network needs its timezone to send a query time. A TRIAS or OJP network needs a requestor_ref, which public servers document, e.g. OpenService. A HAFAS network needs hafas=HafasOptions(...) and its timezone; the bundled ones have both. Entur asks every client for its name in the header ET-Client-Name (company-application) and limits clients without it, so add it to the bundled network: entur.headers.append(Header(name="ET-Client-Name", value="mycompany-myapp")). A network of that protocol searches for locations on the geocoder named in geocoder=, and its answer to trips can be empty at night and still have a later reference to follow. A server that wants a key in an HTTP header gets it through Network(headers=[Header(...)]).

trips returns a Trips record: the list is in trips, and earlier and later are references for more. Pass one as page with the same other arguments to continue the search.

Failures that the server or the query cause are raised as subclasses of publictransport.Error, such as Error.NotFound or Error.RateLimited. Failures of the HTTP exchange are raised as httpx raises them. An answer above 16 MB raises ResponseTooLarge.

A client can be built on an httpx client of your own, Client(http_client=...), for example to use a proxy. That client has to set the User-Agent itself and must not follow redirects.

An application with its own HTTP stack can skip the clients: Network.locations_request(query) returns the request to send, and Network.parse_locations(response) reads the answer. Departures and trips have the same pair.

Known limitations

The model classes are generated by UniFFI, and type checkers stumble over the generated code in two places. Both work at runtime; a typed application needs an ignore comment there.

  • Place.ID("..."), Place.COORDINATE(...) and the TripTime variants are rejected where a Place or TripTime is expected. Each takes its one value as a positional argument.
  • pyright rejects except Error:. Catching a subclass such as Error.NotFound is accepted, and the fields of the subclasses are untyped.

str() of an error shows only its fields and is empty for errors without any, such as Error.RateLimited. Use repr() in messages.

Development

The package is built with maturin from the crate in bindings/uniffi. Inside the repository's nix shell:

uv sync                                          # build the Rust library, install into .venv
uv sync --reinstall-package publictransport      # again after a change to the Rust code
ruff check . && ruff format --check . && pyright
uv run pytest

Metadata

Release files for publictransport 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for publictransport 0.1.1
File Size Uploaded Provenance Actions
publictransport-0.1.1.tar.gz 377.8 kB With provenance Details for publictransport-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for publictransport 0.1.1
File Actions
publictransport-0.1.1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for publictransport-0.1.1-py3-none-win_amd64.whl
publictransport-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for publictransport-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
publictransport-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for publictransport-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
publictransport-0.1.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for publictransport-0.1.1-py3-none-macosx_11_0_arm64.whl
publictransport-0.1.1-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for publictransport-0.1.1-py3-none-macosx_10_12_x86_64.whl

Total release size: 7.2 MB

Release files / publictransport-0.1.1.tar.gz

Download URL publictransport-0.1.1.tar.gz
Size 377.8 kB
Tags Source
SHA-256 checksum
How to use checksums
523a2f25372891dc9ed2d8a9b7cf8fe6e64d49f77717fa2f5446ece599218603
BLAKE2b-256 checksum
How to use checksums
1ce6b0aad89c6c2c86de26422e78419c0f4fd1734adef2a660e67a08f881ef50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / publictransport-0.1.1-py3-none-win_amd64.whl

Download URL publictransport-0.1.1-py3-none-win_amd64.whl
Size 1.2 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
bd80ad9850239d49c7b0bba3ecdf6ca93495b947fe2f1d48546e4d1dcb580ad3
BLAKE2b-256 checksum
How to use checksums
11b045b0c443453ab141f878bc5ca05b1fe3628d60621c60f56713936b2320d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / publictransport-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL publictransport-0.1.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.4 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
2229705cba4f5cb444fe59310e9df76f87d1b5d153af1145facd1241d050a7cc
BLAKE2b-256 checksum
How to use checksums
439008dd70e47b59bc087d4526af0d2223605697482ce91aa300c8b9ca98d4e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / publictransport-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL publictransport-0.1.1-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.5 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
ffb6e2657595ccca914856e3a46c7aba52c33926d16452197d3de2b445aa5db4
BLAKE2b-256 checksum
How to use checksums
1aec24d0faa3447281f97e64c449937ea2869dfad2a9658467ae3f7969f2dad3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / publictransport-0.1.1-py3-none-macosx_11_0_arm64.whl

Download URL publictransport-0.1.1-py3-none-macosx_11_0_arm64.whl
Size 1.3 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ed1b096cec55bf75d6b52ef74b68b8b4f72c7826f6a935002bf882a068e2ffaa
BLAKE2b-256 checksum
How to use checksums
2bd647e6e4486c48cd2f5ef2bf0568f64e3e20e54b343e98e803e293e87ce498
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / publictransport-0.1.1-py3-none-macosx_10_12_x86_64.whl

Download URL publictransport-0.1.1-py3-none-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
3ad59479d42d9316b2de95f6606c3c99716ea2575cb955554f648e1436fd8eb3
BLAKE2b-256 checksum
How to use checksums
b619f47ca5b3ffa13f121f0dc9e870c636ae5c7014bcdf10b96f7e5b971ebd65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for publictransport 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for publictransport-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page