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.3.1.tar.gz (17.3 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.3.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gtfs_digester-0.3.1.tar.gz
  • Upload date:
  • Size: 17.3 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.3.1.tar.gz
Algorithm Hash digest
SHA256 a545444da974388dd07c2620a6949e0938ab2b41a9319cf796df6d0b4df6fcfe
MD5 2260a8d1657acf27c798075481ca1801
BLAKE2b-256 92cb52ba87316ce1510b92802120799a1b07faad9d7b13d4326a808222bb4cfc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gtfs_digester-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 22.2 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 749f5eb3055fef00797d71de7942548b182379b964c35770db1af83c89a12229
MD5 49d3a74eb0cb5509061d969d08b94f18
BLAKE2b-256 09125a1d0d558f6123d42b3b5f512984fc948db7add56662211d0c368343575a

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