A comprehensive Python library for analyzing General Transit Feed Specification (GTFS) data in memory without requiring a database. GTFS Kit leverages Pandas and GeoPandas for data processing and provides comprehensive functionality for working with public transit data including routes, stops, trips, shapes, and calendar information.
pip install gtfs-kitimport gtfs_kit as gkimport gtfs_kit as gk
# Read a GTFS feed from a file or URL
feed = gk.read_feed('path/to/gtfs.zip', dist_units='km')
# Get basic information about the feed
print(gk.describe(feed))
# Get routes as a DataFrame
routes = gk.get_routes(feed)
# Get stops with geometry
stops = gk.get_stops(feed, as_gdf=True)
# Compute statistics for a specific date
date = '20230101'
route_stats = gk.compute_route_stats(feed, dates=[date])
stop_stats = gk.compute_stop_stats(feed, dates=[date])
# Export to GeoJSON
routes_geojson = gk.routes_to_geojson(feed)
stops_geojson = gk.stops_to_geojson(feed)GTFS Kit is built around the Feed class which serves as the primary interface for all GTFS operations. The library is organized into functional modules:
All functions are available both as standalone functions and as methods on Feed instances, providing flexibility for different usage patterns.
Core functionality for loading, manipulating, and exporting GTFS feeds. Includes the main Feed class and functions for reading feeds from files or URLs, listing feed contents, and writing feeds to various formats.
def read_feed(path_or_url, dist_units='km'): ...
def list_feed(path): ...
class Feed:
def copy(self): ...
def to_file(self, path, ndigits=None): ...Statistical analysis, time series computation, and performance metrics for transit operations. Provides comprehensive analysis capabilities for routes, stops, trips, and system-wide metrics across multiple dates and time periods.
def compute_route_stats(feed, dates, **kwargs): ...
def compute_stop_stats(feed, dates, **kwargs): ...
def compute_trip_stats(feed, **kwargs): ...
def compute_route_time_series(feed, dates, **kwargs): ...
def compute_stop_time_series(feed, dates, **kwargs): ...
def compute_feed_stats(feed, dates, **kwargs): ...Geometric processing, spatial analysis, and interactive mapping capabilities. Supports conversion between DataFrame and GeoDataFrame formats, spatial operations, and creation of interactive maps using Folium.
def get_routes(feed, as_gdf=False, use_utm=False, **kwargs): ...
def get_stops(feed, as_gdf=False, use_utm=False, **kwargs): ...
def get_shapes(feed, as_gdf=False, use_utm=False): ...
def map_routes(feed, route_ids=None, **kwargs): ...
def map_stops(feed, stop_ids, **kwargs): ...
def routes_to_geojson(feed, route_ids=None, **kwargs): ...
def stops_to_geojson(feed, stop_ids=None): ...Data cleaning, validation, and transformation utilities for improving GTFS data quality. Includes functions for cleaning IDs, times, route names, and comprehensive feed cleaning operations.
def clean_ids(feed): ...
def clean_times(feed): ...
def clean_route_short_names(feed): ...
def clean(feed): ...
def drop_zombies(feed): ...
def aggregate_routes(feed, **kwargs): ...
def aggregate_stops(feed, **kwargs): ...Constants, helper functions, and miscellaneous utilities for GTFS data manipulation. Includes date/time utilities, geometric calculations, data structure helpers, and configuration constants.
# Constants
GTFS_REF: pd.DataFrame
DIST_UNITS: list
WGS84: str
COLORS_SET2: list
# Helper functions
def datestr_to_date(x, format_str='%Y%m%d', *, inverse=False): ...
def timestr_to_seconds(x, *, inverse=False, mod24=False): ...
def get_convert_dist(dist_units_in, dist_units_out): ...
def almost_equal(f, g): ...