GTFS Blocks
gtfsblocks is a Python package that pieces together GTFS feed data to assemble individual vehicle blocks and compile relevant data from various tables. The code was originally developed to analyze transit bus electrification, but the functionality can be helpful to other applications as well. The package was predominantly built off of the GTFS processing code from ebusopt.
Some core functions include:
- Reading static GTFS tables into Pandas
DataFrameobjects and performing a bit of basic validation that necessary columns are populated while dropping what isn't needed. - Parsing the
calendar.txtandcalendar_dates.txtfiles to identify the activeservice_idvalues on each day of service. - Merging together trip-level data from different GTFS tables for easy manipulation and analysis. For example:
- Adding trip start and end times from
stop_times.txt - Adding trip start and end locations from
shapes.txt- Esimating deadhead distances between consecutive trips based on these coordinates
- Adding trip distances calculated from the lat/lon coordinates in
shapes.txt
- Adding trip start and end times from
See this gist for an overview of core functionality as well as the example usage below. Documentation is a work in progress.
Installation
gtfsblocks is installable via pip:
pip install gtfsblocks
Example Usage
It's easy to read in a GTFS feed with gtfsblocks. Just supply the path to the directory where unzipped GTFS files are housed:
from gtfsblocks import Feed
gtfs = Feed.from_dir('/path/to/your/data')
This will load all relevant files into memory as Pandas DataFrames. Future releases may take advantage of partridge for better memory management.
From here, you can access predictably named tables like gtfs.trips_df or gtfs.stop_times_df, or call various methods on Feed to perform some transformations and aggregations for you.
Getting active trips on a particular day
# Get a Pandas Series of the number of trips per day in the scope of these files
trips_per_day = gtfs.get_n_trips_per_day()
# Filter down trips.txt to just those happening on a particular day
test_date = '2/25/25'
day_trips = gtfs.get_trips_from_date(test_date)
Only include blocks serving a specific set of routes
from gtfsblocks import filter_blocks_by_route
routes = ['D Line', 'E Line']
route_trips = filter_blocks_by_route(
trips=day_trips,
routes=routes,
route_method=route_method,
route_column='route_short_name'
)
Add data from other GTFS tables to trips DataFrame
# Add all trip data columns (e.g. locations and distances)
route_trips = gtfs.add_trip_data(route_trips, test_date)
Estimate deadhead distance between trips
from gtfsblocks import add_deadhead
trips_with_dh = add_deadhead(route_trips)
Plot the trips on an interactive Plotly map
from gtfsblocks import plot_trips_and_terminals
fig = plot_trips_and_terminals(
trips_df=route_trips,
shapes_df=gtfs.shapes_df
)
Metadata
Release files for gtfsblocks 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gtfsblocks-0.1.5.tar.gz | 15.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gtfsblocks-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.9 kB
Release files / gtfsblocks-0.1.5.tar.gz
| Download URL | gtfsblocks-0.1.5.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9512b5cc6e25d8b9dc535838de722ff909440acff2f340522e0cd9c4885f09f
|
|
BLAKE2b-256 checksum How to use checksums |
676299027ca22343e55415b4d69487cadebbb1bdfb73f383b503f817e945ff4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 13, 2026.
Transparency logRelease files / gtfsblocks-0.1.5-py3-none-any.whl
| Download URL | gtfsblocks-0.1.5-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1b7e15f0d155a0b1aae38a8ddff8978774f3ca9199933f69829aff695e1c2a6
|
|
BLAKE2b-256 checksum How to use checksums |
ddfe6e3441cd95fcf6bcb704cf3ddf41939991ea3a966ff98700779bba90447d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 13, 2026.
Transparency log