GTFS cleanup and transformation utilities
Project description
gtfs-tools
GTFS cleanup and transformation utilities for improving feed quality and consistency.
Features
- Clean Feed: Remove problematic Unicode characters (non-breaking spaces, zero-width chars, etc.)
- Fix Routes: Convert ALL CAPS route names to Title Case using route descriptions as reference
- Fix Blocks: Clear block_id for trips with overlapping stop times (prevent impossible schedules)
- Round Shapes: Round geographic coordinates and distances to appropriate precision
Installation
pip install .
Or with development mode:
pip install -e .
Usage
As a Library
from gtfs_normalizer import clean_feed, fix_route_names, fix_overlapping_blocks, round_shapes
from pathlib import Path
feed_dir = Path("feed")
# Clean invisible Unicode whitespace
clean_feed(feed_dir)
# Fix ALL CAPS route names
fix_route_names(feed_dir)
# Fix overlapping block assignments
fix_overlapping_blocks(feed_dir)
# Round geographic/distance values
round_shapes(feed_dir)
As Command-Line Tools
# Clean feed
gtfs-clean ./feed
# Fix route names
gtfs-fix-routes ./feed
# Fix overlapping blocks
gtfs-fix-blocks ./feed
# Round shapes
gtfs-round-shapes ./feed
Module Details
clean_feed
Removes problematic whitespace characters:
- U+00A0 (non-breaking space)
- U+200B (zero-width space)
- U+200C (zero-width non-joiner)
- U+200D (zero-width joiner)
- U+FEFF (zero-width no-break space / BOM)
Usage:
from gtfs_normalizer import clean_feed
clean_feed("feed")
fix_route_names
Converts ALL CAPS route names to Title Case using route_desc as reference:
- Splits route name by " - " separator
- Finds each part in route_desc (case-insensitive)
- Reconstructs with proper casing from description
- Removes
route_descwhen it duplicatesroute_long_name
Usage:
from gtfs_normalizer import fix_route_names
fix_route_names("feed")
fix_overlapping_blocks
Clears block_id for trips with overlapping stop times in the same block:
- Groups trips by block and service
- Calculates trip start/end times from stop_times
- Detects overlaps (same physical vehicle in two places simultaneously)
- Clears block_id for conflicting trips
Usage:
from gtfs_normalizer import fix_overlapping_blocks
fix_overlapping_blocks("feed")
round_shapes
Rounds geographic and distance precision:
- shapes.txt: lat/lon to 6 decimals (~1.1m accuracy), distances to 2 decimals
- stop_times.txt: distances to 2 decimals
Usage:
from gtfs_normalizer import round_shapes
round_shapes("feed")
Requirements
- Python 3.11+
- No external dependencies
Integration Example
For use in GitHub Actions workflows or local scripts:
import logging
from pathlib import Path
from gtfs_normalizer import clean_feed, fix_route_names, fix_overlapping_blocks, round_shapes
logging.basicConfig(level=logging.INFO)
feed_dir = Path("feed")
# Apply all transformations in sequence
clean_feed(feed_dir)
fix_route_names(feed_dir)
fix_overlapping_blocks(feed_dir)
round_shapes(feed_dir)
print("GTFS feed processing completed")
License
MIT
Project details
Release history Release notifications | RSS feed
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_normalizer-0.0.1.dev1.tar.gz.
File metadata
- Download URL: gtfs_normalizer-0.0.1.dev1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d374727c924f5b0d90900a7f85d0f660f19b616dbe2e4b5c4dc08dc16932059
|
|
| MD5 |
827b46c48d215a59784763c66ade33c0
|
|
| BLAKE2b-256 |
b2d5aeaf6685ae4e02a71d02fee1f7d3574ef4a4454ac111f2259466759eeedf
|
File details
Details for the file gtfs_normalizer-0.0.1.dev1-py3-none-any.whl.
File metadata
- Download URL: gtfs_normalizer-0.0.1.dev1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b175a06d364753f53b4f2214ce5cbeea867fad0ac90c6820b14c9ad52dc02134
|
|
| MD5 |
a5453161e0ca51acd13c83f02433ac9a
|
|
| BLAKE2b-256 |
1e59415b71e571fe5d3abdec103b92f646b6b310014dc4f61dfa2c2de38e0394
|