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):
print(departure.scheduled_time, departure.line.name, departure.direction)
found = client.trips(vvo, stops[0], stops[1])
more = client.trips(vvo, stops[0], stops[1], page=found.later)
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, and Location.timezone names the zone to show them in. 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 theTripTimevariants are rejected where aPlaceorTripTimeis expected. Each takes its one value as a positional argument.- pyright rejects
except Error:. Catching a subclass such asError.NotFoundis 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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| publictransport-0.1.0.tar.gz | 374.5 kB | With provenance | Details for publictransport-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| publictransport-0.1.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for publictransport-0.1.0-py3-none-win_amd64.whl |
| publictransport-0.1.0-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.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| publictransport-0.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details for publictransport-0.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| publictransport-0.1.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for publictransport-0.1.0-py3-none-macosx_11_0_arm64.whl |
| publictransport-0.1.0-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for publictransport-0.1.0-py3-none-macosx_10_12_x86_64.whl |
Total release size: 7.2 MB
Release files / publictransport-0.1.0.tar.gz
| Download URL | publictransport-0.1.0.tar.gz |
|---|---|
| Size | 374.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb217edd8b0092bc13d9693787ae91896e88b9d7b2d9c5cda26e19df19df2677
|
|
BLAKE2b-256 checksum How to use checksums |
97dadc26ec24103e69679486de28c59969cb7efbd5c24441610c37a81e09873f
|
| 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 logRelease files / publictransport-0.1.0-py3-none-win_amd64.whl
| Download URL | publictransport-0.1.0-py3-none-win_amd64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
105c8cb6c6bc63e7a2ec4ca256c8e9698070afc3e19d5367c1f0561e48e84053
|
|
BLAKE2b-256 checksum How to use checksums |
96648cbaf7198223e396a69af7f7b07064892eb04d311abe60704fdb6e5d837b
|
| 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 logRelease files / publictransport-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | publictransport-0.1.0-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 |
273522a72bc4f99aa416ef2a0d78e22b2a8c4e44fcc56c71944c769363a4eeee
|
|
BLAKE2b-256 checksum How to use checksums |
57fba29136897c32227d6e4ee5471cca46be15be2eedba5d70e643183bd973e0
|
| 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 logRelease files / publictransport-0.1.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | publictransport-0.1.0-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 |
97c6b72a3f7e533294e1561c685e0b239c9362e12872823f7fb58d4d1799a362
|
|
BLAKE2b-256 checksum How to use checksums |
325defff8860efe90316498d8954927739821f85386b2fbccda221b9d1cdfe02
|
| 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 logRelease files / publictransport-0.1.0-py3-none-macosx_11_0_arm64.whl
| Download URL | publictransport-0.1.0-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 |
c1a098717b0c18a9c5984db3ed334ace1c67468cf781b474b6c258982370c411
|
|
BLAKE2b-256 checksum How to use checksums |
cfe43fe5e65a54b1bfabbb37c63af9c8bec1a3f4bc7d935aad16868bd9478600
|
| 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 logRelease files / publictransport-0.1.0-py3-none-macosx_10_12_x86_64.whl
| Download URL | publictransport-0.1.0-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 |
f2e342a788b71569012dfd08686aa92df5d31db62ecbb6c3d807a20496d4efe5
|
|
BLAKE2b-256 checksum How to use checksums |
62c8465c17acefc7c6f3c72777c8348ddca6da5464856b33fd1b18f72ac3237d
|
| 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 logSecurity for publictransport 0.1.0
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.
Attestation for publictransport-0.1.0.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 logA 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.