Skip to main content

Canonicalization, fingerprinting, and change detection for GTFS Schedule feeds

Project description

gtfs-digester

Canonicalization, fingerprinting, and change detection for GTFS Schedule feeds.

What It Does

Takes a GTFS zip and produces:

  • A content fingerprint (BLAKE3 merkle hash) — identical for semantically identical feeds regardless of zip metadata, file ordering, CSV whitespace, or time formatting
  • Canonical Arrow tables for each file — normalized, sorted by primary key, all values as strings
  • Per-file hashes for efficient hierarchical change detection
  • Archive diffs — added/removed/modified files and rows by primary key
  • Exploded parquet storage — write/read from local or cloud (GCS, S3) via fsspec

All files and columns are preserved, including non-standard ones.

Install

pip install gtfs-digester
# or
uv add gtfs-digester

CLI

# Fingerprint a feed
gtfs-digester digest google_transit.zip
# Fingerprint: v1:abc123...
# Files: 11
#   agency.txt        1 rows
#   stops.txt      9245 rows
#   ...

# JSON output or just the hash
gtfs-digester digest --json google_transit.zip
gtfs-digester digest --quiet google_transit.zip

# Diff two feeds (exit code 1 if different)
gtfs-digester diff old.zip new.zip

# Write as exploded parquet
gtfs-digester write google_transit.zip ./output --schedule-url https://example.com/gtfs.zip

# Produce a normalized GTFS zip
gtfs-digester normalize messy.zip clean.zip

Python API

from gtfs_digester import GTFSArchive

# Load and fingerprint
archive = GTFSArchive.from_zip("google_transit.zip")
print(archive.fingerprint.hex())  # v1:abc123...

# Access canonical tables
stops = archive.arrow_table("stops.txt")
print(stops.num_rows)

# Compare two feed versions
old = GTFSArchive.from_zip("old.zip")
new = GTFSArchive.from_zip("new.zip")
diff = old.diff(new)
print(diff.is_identical)
for f in diff.modified_files:
    fd = diff.file_diff(f)
    print(f"{f}: {fd.summary()}")

# Write as exploded parquet
from gtfs_digester import write_exploded
write_exploded(archive, "gs://bucket/schedules/feed-1", schedule_url="https://...")

How Fingerprinting Works

  1. Each .txt file is parsed to a PyArrow table (all strings)
  2. Columns reordered per GTFS spec (unknown columns preserved, sorted alphabetically after spec columns)
  3. Values normalized: whitespace stripped, times zero-padded (9:05:0009:05:00)
  4. Rows sorted by primary key (numeric columns sorted numerically, not lexicographically)
  5. Canonical CSV serialized and BLAKE3 hashed per file
  6. Archive fingerprint = BLAKE3 of sorted filename:hash pairs (merkle tree)

Unknown files (not in the GTFS spec) are preserved with lexicographic row sorting.

Storage Layout

write_exploded() produces a version-first directory:

base_path/
  _feed_digest={v1:abc...}/
    agency.parquet
    stops.parquet
    routes.parquet
    trips.parquet
    stop_times.parquet
    ...
    metadata.json       # provenance + digester info, written last (commit marker)

DuckDB reads across versions with hive partitioning:

SELECT * FROM read_parquet('base_path/_feed_digest=*/stops.parquet', hive_partitioning=true);

Development

uv sync --group dev
uv run pytest tests/ -k "not Real"   # unit tests (~0.5s)
uv run pytest tests/                  # includes real feed integration tests

License

MIT

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

gtfs_digester-0.2.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gtfs_digester-0.2.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file gtfs_digester-0.2.0.tar.gz.

File metadata

  • Download URL: gtfs_digester-0.2.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gtfs_digester-0.2.0.tar.gz
Algorithm Hash digest
SHA256 192353e8ed38e34907c3cb926cb26e9921553767dd9375730cccb691e730c02e
MD5 d855d93fc4daae4be8569502148e031a
BLAKE2b-256 5b075dbea1922b98adf60377449cf1a27568082bef90a74814ad6a42fed0c4de

See more details on using hashes here.

File details

Details for the file gtfs_digester-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gtfs_digester-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gtfs_digester-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25b3ebc0aa98ac0889b3c6f031ae5d3fa67981d24ee788140ef1ca6046f35a3e
MD5 9dcfc1738674e9a2e5ce52c67a506e00
BLAKE2b-256 9091bc4a0b7dd666c3f43635e30c9495ae24cbd791f3b0ca331388379b262206

See more details on using hashes here.

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