Fast GTFS validator written in Rust
Project description
GTFS Guru Python
High-performance GTFS feed validator with Python bindings. Written in Rust, exposed via PyO3.
Installation
pip install gtfs-guru
From Source
pip install maturin
maturin build --release
pip install target/wheels/gtfs_guru-*.whl
Quick Start
import gtfs_guru
# Validate a GTFS feed
result = gtfs_guru.validate("/path/to/gtfs.zip")
print(f"Valid: {result.is_valid}")
print(f"Errors: {result.error_count}")
print(f"Warnings: {result.warning_count}")
# Print errors
for error in result.errors():
print(f"{error.code}: {error.message}")
API Reference
Functions
validate(path, country_code=None, date=None) -> ValidationResult
Validate a GTFS feed.
Parameters:
path(str): Path to GTFS zip file or directorycountry_code(str, optional): ISO country code (e.g., "US", "RU")date(str, optional): Validation date in YYYY-MM-DD format
Returns: ValidationResult object
Example:
result = gtfs_guru.validate(
"/path/to/gtfs.zip",
country_code="US",
date="2025-01-15"
)
async validate_async(path, country_code=None, date=None, on_progress=None) -> ValidationResult
Validate a GTFS feed asynchronously (non-blocking).
Parameters:
path(str): Path to GTFS zip file or directorycountry_code(str, optional): ISO country codedate(str, optional): Validation date in YYYY-MM-DD formaton_progress(Callable[[ProgressInfo], None], optional): Callback for progress updates
Example:
import asyncio
async def main():
def on_progress(info):
print(f"{info.stage}: {info.current}/{info.total}")
result = await gtfs_guru.validate_async(
"/path/to/gtfs.zip",
on_progress=on_progress
)
asyncio.run(main())
version() -> str
Get validator version.
>>> gtfs_guru.version()
'0.9.0'
notice_codes() -> list[str]
Get list of all available notice codes.
>>> len(gtfs_guru.notice_codes())
164
>>> gtfs_guru.notice_codes()[:3]
['attribution_without_role', 'bidirectional_exit_gate', 'block_trips_with_overlapping_stop_times']
notice_schema() -> dict
Get schema for all notice types with descriptions and severity levels.
>>> schema = gtfs_guru.notice_schema()
>>> schema['missing_required_field']
{'severity': 'ERROR', 'description': '...'}
Classes
ValidationResult
Result of GTFS validation.
Attributes:
| Attribute | Type | Description |
|---|---|---|
is_valid |
bool |
True if no errors |
error_count |
int |
Number of errors |
warning_count |
int |
Number of warnings |
info_count |
int |
Number of info notices |
validation_time_seconds |
float |
Validation time in seconds |
notices |
list[Notice] |
All validation notices |
Methods:
# Get notices by severity
errors = result.errors() # List[Notice]
warnings = result.warnings() # List[Notice]
infos = result.infos() # List[Notice]
# Filter by notice code
notices = result.by_code("missing_required_field") # List[Notice]
# Export
result.save_json("/path/to/report.json")
result.save_html("/path/to/report.html")
json_str = result.to_json() # str
report = result.to_dict() # dict
Notice
A single validation notice.
Attributes:
| Attribute | Type | Description |
|---|---|---|
code |
str |
Notice code (e.g., "missing_required_field") |
severity |
str |
"ERROR", "WARNING", or "INFO" |
message |
str |
Human-readable message |
file |
str | None |
GTFS filename |
row |
int | None |
CSV row number |
field |
str | None |
Field name |
Methods:
# Get context field
value = notice.get("fieldName") # Any | None
# Get all context
ctx = notice.context() # dict[str, Any]
Examples
Basic Validation
import gtfs_guru
result = gtfs_guru.validate("/path/to/gtfs.zip")
if result.is_valid:
print("Feed is valid!")
else:
print(f"Found {result.error_count} errors")
for error in result.errors():
print(f" - {error.code}: {error.message}")
Detailed Analysis
from collections import Counter
result = gtfs_guru.validate("/path/to/gtfs.zip")
# Count notices by code
error_counts = Counter(e.code for e in result.errors())
for code, count in error_counts.most_common(10):
print(f"{code}: {count}")
# Find all missing required fields
for notice in result.by_code("missing_required_field"):
file = notice.file
field = notice.get("fieldName")
row = notice.row
print(f"{file}:{row} - missing {field}")
Save Reports
result = gtfs_guru.validate("/path/to/gtfs.zip")
# Save JSON report (same format as Java validator)
result.save_json("report.json")
# Save HTML report
result.save_html("report.html")
# Get as Python dict
report = result.to_dict()
summary = report["summary"]
print(f"Agencies: {summary.get('agencies', [])}")
print(f"Routes: {summary.get('routes', {}).get('count', 0)}")
Validation with Options
# Validate for specific country (affects some rules)
result = gtfs_guru.validate(
"/path/to/gtfs.zip",
country_code="DE"
)
# Validate as of specific date
result = gtfs_guru.validate(
"/path/to/gtfs.zip",
date="2025-06-01"
)
Supported Platforms
| Platform | Architecture | Python |
|---|---|---|
| macOS | ARM64 (M1/M2) | 3.8+ |
| macOS | x86_64 (Intel) | 3.8+ |
| Windows | x86_64 | 3.8+ |
| Linux | x86_64 | 3.8+ |
Performance
Typical validation times (compared to Java validator):
| Feed Size | Java | Rust/Python |
|---|---|---|
| Small (<1MB) | ~2s | ~0.05s |
| Medium (10MB) | ~10s | ~0.5s |
| Large (100MB) | ~60s | ~3s |
License
Apache-2.0
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_guru-0.9.0.tar.gz.
File metadata
- Download URL: gtfs_guru-0.9.0.tar.gz
- Upload date:
- Size: 243.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6970ddcabb8110221dfba836901cdcdc254ff1c64fb85e482d1df938dc4b0f13
|
|
| MD5 |
846ef70eac344b84e562ded83c73fef5
|
|
| BLAKE2b-256 |
c214f927a80736e9c80d85d79bdb0f5c0964e1189d733de50f60f90593ef7861
|
File details
Details for the file gtfs_guru-0.9.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gtfs_guru-0.9.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
017149d458abd21e3b5ce327d491b21831f72791dce40d9fa62fce68bf64ef1f
|
|
| MD5 |
728d3104a0a7bf10585bf7ed2d4326ea
|
|
| BLAKE2b-256 |
2dc4475f177167b4444045042e4c982f509b888de75e00edfdba3f1149bcaeb5
|