API reference#

fetch() is the main entry point: it runs the whole acquisition pipeline for an area of interest and returns a FetchResult. Every stage is also available on its own — the catalog client, the OSM fetcher, and the validate/repair/crop functions.

The pipeline#

fetch(aoi[, when, modes, repair, crop, ...])

Fetch everything cafein needs for an AOI in one call.

FetchResult(osm_pbf, feeds, reports, ...)

What the pipeline produced for one AOI.

FetchResult.to_cafein(**options)

Build a routable cafein.TransportNetwork from this result.

FetchResult.to_pyrosm(**options)

Open the OSM extract as a pyrosm.OSM reader.

The feed catalog#

MobilityDatabase([refresh_token, cache_dir, ...])

Synchronous client for the Mobility Database catalog API.

MobilityDatabase.search_feeds([aoi, ...])

Search GTFS feeds in the Mobility Database catalog.

MobilityDatabase.feed(feed_id)

Fetch a single feed by its catalog ID.

MobilityDatabase.datasets(feed, *[, limit])

List catalogued dataset versions of a feed, newest first.

MobilityDatabase.dataset_for(feed, when)

Pick the dataset whose published service range covers a date.

MobilityDatabase.download(dataset[, directory])

Download a dataset zip with checksum verification and caching.

MobilityDatabase.download_latest(feed[, ...])

Download the latest hosted dataset zip of a feed.

MobilityDatabase.validation_report(dataset)

Fetch the hosted canonical-validator JSON report for a dataset.

MobilityDatabase.close()

Close the underlying HTTP session.

Feed(id, provider, status, official, ...)

A GTFS feed catalogued in the Mobility Database.

Dataset(id, feed_id, hosted_url, ...)

One downloadable version of a feed, with its service date range.

OSM extracts#

fetch_pbf(aoi, *[, crop, directory, ...])

Download (and by default crop) the OSM extract covering an AOI.

Validation, repair and cropping#

validate_feed(path, *[, max_entry_bytes, ...])

Validate a GTFS zip and return the collected notices.

repair_feed(path, output, **options)

Repair a GTFS zip under the gtfstidy contract and write the result.

crop_feed(path, output, *[, aoi, ...])

Crop a GTFS zip to an area of interest and/or a date window.

Reporting#

build_report(validation, *[, hosted, provenance])

Merge a validate_feed result with an optional hosted report.

parity_summary(report)

Summarize local-versus-canonical agreement in a merged report.

render_markdown(report)

Render a merged report as Markdown.

render_html(report)

Render a merged report as a self-contained HTML page.

Exceptions#

TransitioError

Base class for all transitio-specific errors.

MissingTokenError

No Mobility Database refresh token is available.

DownloadError

A dataset cannot be downloaded or fails checksum verification.

ExtractNotFoundError

No OSM extract covers the requested area.