CLI tool to fetch, archive, process and explore GTFS-RT data
Project description
gtfs-cli
CLI tool to fetch, process, and explore GTFS transit data — both realtime (GTFS-RT) and static schedules. Follows Unix philosophy: each command does one thing and writes to stdout, composing naturally with tools like curl, unzip, and jq.
Installation
uv tool install gtfs-cli
After installation, the gtfs-cli command is available globally.
Commands
static info
Inspect a static GTFS feed (a folder of .txt files). Shows agency, valid dates, feed age, stop/route/trip counts, route types, service days, and file inventory.
# Download and unzip a feed, then inspect it
curl -L "https://ckan0.cf.opendata.inter.prod-toronto.ca/dataset/7795b45e-e65a-4465-81fc-c36b9dfff169/resource/cfb6b2b8-6191-41e3-bda1-b175c51148cb/download/TTC%20Routes%20and%20Schedules%20Data.zip" -o ttc.zip
unzip ttc.zip -d ttc/
gtfs-cli static info ttc/
# Inspect the current directory
gtfs-cli static info
For all available options, run:
gtfs-cli static info --help
fetch
Fetch a GTFS-RT feed from a URL or local file and output it as JSON.
# Fetch live trip updates
gtfs-cli fetch "https://gtfsrt.ttc.ca/trips/update?format=binary"
# Fetch vehicle positions
gtfs-cli fetch "https://gtfsrt.ttc.ca/vehicles/position?format=binary"
# Fetch service alerts
gtfs-cli fetch "https://gtfsrt.ttc.ca/alerts/all?format=binary"
# Inspect a previously saved .pb file
gtfs-cli fetch trips.pb
Filtering with jq:
# List all active alerts
gtfs-cli fetch "https://gtfsrt.ttc.ca/alerts/all?format=binary" | jq '.entity[] | .alert'
# Count entities in a feed
gtfs-cli fetch "https://gtfsrt.ttc.ca/trips/update?format=binary" | jq '.entity | length'
# Extract all trip IDs
gtfs-cli fetch "https://gtfsrt.ttc.ca/trips/update?format=binary" \
| jq '[.entity[].trip_update.trip.trip_id]'
Watch mode — continuously poll a feed and stream NDJSON (one JSON object per line):
# Poll every 30 seconds
gtfs-cli fetch --watch 30 "https://gtfsrt.ttc.ca/trips/update?format=binary"
# Count entities on each snapshot
gtfs-cli fetch --watch 30 "https://gtfsrt.ttc.ca/trips/update?format=binary" \
| jq --unbuffered '.entity | length'
# Save a long-running collection to a file
gtfs-cli fetch --watch 30 "https://gtfsrt.ttc.ca/trips/update?format=binary" \
>> snapshots.ndjson
Watch mode handles transient failures gracefully: HTTP and network errors are retried with exponential backoff (1s → 2s → 4s … capped at 60s). Stop with Ctrl+C or SIGTERM.
For all available options, run:
gtfs-cli fetch --help
Development
# Install dependencies
uv sync
# Run a command
uv run gtfs-cli fetch "https://gtfsrt.ttc.ca/trips/update?format=binary"
# Run tests
uv run pytest tests/ -v
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gtfs_cli-0.2.0.tar.gz.
File metadata
- Download URL: gtfs_cli-0.2.0.tar.gz
- Upload date:
- Size: 421.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5bc46340a8c227a621838a0e8b25a78b06767d3997a7a0cf2f113439bf68e8c
|
|
| MD5 |
3797671b072c004ac201f18149f72320
|
|
| BLAKE2b-256 |
dc2471c0d3fa49e866e710450044a6be713efa8f24e8a0c4db8f916fb965cce5
|
File details
Details for the file gtfs_cli-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gtfs_cli-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f4ac6f9fcbc4eb863440686f30a77bf61ac074e2b398c1d8f78112328507c1c
|
|
| MD5 |
e3df4bd0fe49750de7f920b93bf0a951
|
|
| BLAKE2b-256 |
3ba4435abab441c57bd210ad392235eff34015426d9424052a99aad0dda1a7f3
|