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.4.0.tar.gz (18.0 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.4.0-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gtfs_digester-0.4.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.4.0.tar.gz
Algorithm Hash digest
SHA256 1d0a83cb53a885a713781555cd508d3e4ffd7937a52241501d23e61e41cfbfa6
MD5 8ed086293456db76d7e0335fcc6b189b
BLAKE2b-256 dea5a992708e8362a16ef7c81bb6e53bf3083103cc240dc735ce20f138dfa290

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gtfs_digester-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c38a48a399e97ca7eb90efba344baa27fa4bcaccf43eae02f75f62a43e0cb3d
MD5 bc5d1a16a446110e68fd51f326580faf
BLAKE2b-256 c137cdf7b27afd0a0cb614ee276683af20c902b5cacec2a87a878763dfe1509a

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