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 documentation has this guide with a short program for each kind of request, which are also in examples.

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.2

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.2
File Size Uploaded Provenance Actions
publictransport-0.1.2.tar.gz 381.5 kB With provenance Details for publictransport-0.1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for publictransport 0.1.2
File Actions
publictransport-0.1.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for publictransport-0.1.2-py3-none-win_amd64.whl
publictransport-0.1.2-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.2-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
publictransport-0.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for publictransport-0.1.2-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
publictransport-0.1.2-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for publictransport-0.1.2-py3-none-macosx_11_0_arm64.whl
publictransport-0.1.2-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for publictransport-0.1.2-py3-none-macosx_10_12_x86_64.whl

Total release size: 7.2 MB

Release files / publictransport-0.1.2.tar.gz

Download URL publictransport-0.1.2.tar.gz
Size 381.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0266d52dbb5a00f3bff1b9cd8f251bdf5ea2e034511ce5e8602a8c069882c43e
BLAKE2b-256 checksum
How to use checksums
d0c8f609d090b6b1d4168ba03bd4acce38134bc9b7818a56521004d5b1c9766d
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 20, 2026.

Transparency log

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

Download URL publictransport-0.1.2-py3-none-win_amd64.whl
Size 1.2 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
bc16db33f370fa2b54e5bd519cbc723360497a2b395b486ebbee2b4c91769576
BLAKE2b-256 checksum
How to use checksums
6868c922ceaf0770e434a5dec67d7259071f25892f973178371ca88960cc90ad
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 20, 2026.

Transparency log

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

Download URL publictransport-0.1.2-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
40264171c9a6622c6e02f6f4ebbd71c59cd59efabf5f9ae97911529b4ea60bfd
BLAKE2b-256 checksum
How to use checksums
f82260c5a19b9dcd551da405ec13a0f2552d2675d4c2a97efceea44dd7490c09
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 20, 2026.

Transparency log

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

Download URL publictransport-0.1.2-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
da8a2941ed8502431300575cdc4c0a6cab9426dd8559dc8d2b39f97f33ac3fa9
BLAKE2b-256 checksum
How to use checksums
7a52114f59a0555336aa5bf3dfe5e4674b78f627b897e577422749849af508c2
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 20, 2026.

Transparency log

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

Download URL publictransport-0.1.2-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
8c3a07beaa778196b57b5a0b559904a90b870b6d3859d0e79ff1bca8a27b1450
BLAKE2b-256 checksum
How to use checksums
74165a065c00733c17d35d2de28393596987293e42d5a00e496277f4840a776f
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 20, 2026.

Transparency log

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

Download URL publictransport-0.1.2-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
5917af19ed62dfe1a1ba3be46e198e63a5c22c5847a1c16f7cd67152cb9c6148
BLAKE2b-256 checksum
How to use checksums
d8ebaef3b37eac548a994206c959c2b42ca3b54c52dd424818fbf4bfe3566527
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 20, 2026.

Transparency log

Security for publictransport 0.1.2

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.2.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 20, 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