Python bindings for the nigiri transit routing library
Project description
PyNigiri - Python Bindings for Nigiri Transit Routing Library
Complete Python bindings for the nigiri C++ transit routing library.
Status
✅ Production Ready - All core functionality is available and tested.
- ✅ 23 unit tests passing
- ✅ Clean integer-based time API
- ✅ Routing verified working with test GTFS data
Features
- Data Loading: Load GTFS, GTFS-RT, HRD, and NeTEx transit data
- Routing: Fast RAPTOR-based public transit routing
- Real-time Updates: Apply GTFS-RT trip updates and alerts
- All Transport Types: Support for all public transit modes (bus, train, tram, ferry, etc.)
Building
The bindings are built as part of the main nigiri build system:
cd nigiri
cmake -B build -DPYTHON_BINDING=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
cmake --build build --target pynigiri -j8
The compiled module will be at: build/python/pynigiri.cpython-*.so
Usage
import sys
sys.path.insert(0, 'build/python')
import pynigiri as ng
from datetime import datetime, date
# Load GTFS data (use current year for your data)
current_year = date.today().year
sources = [ng.TimetableSource("gtfs", "/path/to/gtfs")]
timetable = ng.load_timetable(sources, f"{current_year}-01-01", f"{current_year}-12-31")
# Find locations
start_loc = timetable.find_location("STATION_A_ID")
dest_loc = timetable.find_location("STATION_B_ID")
# Create routing query
query = ng.Query()
# Convert datetime to minutes since epoch
query_time = datetime(current_year, 1, 15, 10, 0, 0)
query.start_time = int(query_time.timestamp()) // 60
# Set start/destination with integer offsets (0 minutes offset)
query.start = [ng.Offset(start_loc, 0, 0)]
query.destination = [ng.Offset(dest_loc, 0, 0)]
query.max_transfers = 6
query.max_travel_time = 600 # 10 hours in minutes
query.start_match_mode = ng.LocationMatchMode.EQUIVALENT
query.dest_match_mode = ng.LocationMatchMode.EQUIVALENT
# Run routing
journeys = ng.route(timetable, query)
# Process results
for journey in journeys:
print(f"Transfers: {journey.transfers}")
print(f"Travel time: {journey.travel_time()} minutes")
for leg in journey.legs:
# Use getattr for 'from' (Python keyword)
from_loc = getattr(leg, 'from')
from_name = timetable.get_location_name(from_loc)
to_name = timetable.get_location_name(leg.to)
# Convert minute timestamps to datetime for display
dep_time = datetime.fromtimestamp(leg.dep_time * 60)
arr_time = datetime.fromtimestamp(leg.arr_time * 60)
print(f" {from_name} -> {to_name}")
print(f" {dep_time.strftime('%H:%M')} -> {arr_time.strftime('%H:%M')}")
Available Types
Enums
Clasz: Transport class (REGIONAL, LONG_DISTANCE, SUBWAY, TRAM, BUS, etc.)LocationType: Location types (STATION, TRACK, GENERATED_TRACK)EventType: Event types (DEP, ARR)Direction: Search direction (FORWARD, BACKWARD)LocationMatchMode: Location matching modes for routingEXACT: Match only the exact platform/stop specifiedEQUIVALENT: Match all equivalent stops at a station (recommended for most routing)ONLY_CHILDREN: Match all child stops of a parent station
Core Types
Timetable: Main timetable data structureQuery: Routing query configurationJourney: Routing result with legsLoaderConfig: Configuration for data loadingRtTimetable: Real-time timetable
Functions
load_timetable(): Load transit dataroute(): Perform routing querygtfsrt_update_from_bytes(): Apply GTFS-RT updates from bytesgtfsrt_update_from_string(): Apply GTFS-RT updates from stringgtfsrt_update_from_file(): Apply GTFS-RT updates from file
Testing
Run the test suite to verify the bindings work correctly:
cd nigiri/python
pytest tests/
Expected output:
======================== 23 passed ========================
All tests should pass without any warnings or issues.
Installation via pip
Install the package using pip:
cd python
pip install .
For development (editable install):
pip install -e .
Implementation Notes
- Built with pybind11 v2.11.1
- Requires C++23 compiler (GCC 13+ or Clang 16+)
- Uses CMake for build configuration
- All static libraries compiled with
-fPICfor shared library compatibility - Strong type wrappers for type safety (LocationIdx, TransportIdx, etc.)
Files
src/main.cc: Module entry pointsrc/types.cc: Core types and enumssrc/timetable.cc: Timetable accesssrc/loader.cc: Data loadingsrc/routing.cc: Routing algorithmssrc/rt.cc: Real-time updatespybind_common.h: Common headers
License
Same as nigiri - MIT License
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 pynigiri-0.1.2.tar.gz.
File metadata
- Download URL: pynigiri-0.1.2.tar.gz
- Upload date:
- Size: 30.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5053e4b75c20331c069905da491dab906fd1139a45532bca680d37f0915e9220
|
|
| MD5 |
32ed9f6c532892e6cb051edd4be49998
|
|
| BLAKE2b-256 |
235cfd035265bda8c6f932764203a7f5f95dc4f999acbfc869dcd2f8cdb247f9
|
Provenance
The following attestation bundles were made for pynigiri-0.1.2.tar.gz:
Publisher:
wheels.yml on 96hoshi/nigiri
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pynigiri-0.1.2.tar.gz -
Subject digest:
5053e4b75c20331c069905da491dab906fd1139a45532bca680d37f0915e9220 - Sigstore transparency entry: 842547398
- Sigstore integration time:
-
Permalink:
96hoshi/nigiri@d6cdda0fdb0b90e1a116c7af054cb6ed4cdf5577 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/96hoshi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@d6cdda0fdb0b90e1a116c7af054cb6ed4cdf5577 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pynigiri-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pynigiri-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.7 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cadf9622d7f036ae605a5a7660ac5521ea2bf2f93f28f6d7e875d55372c689f
|
|
| MD5 |
9185cf41632efc82dc738ef2db7317df
|
|
| BLAKE2b-256 |
38ce8455e2fc656500aeda29c5dc0c63115eac771eb8002a8bf98d548d3a1755
|
Provenance
The following attestation bundles were made for pynigiri-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
wheels.yml on 96hoshi/nigiri
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pynigiri-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
8cadf9622d7f036ae605a5a7660ac5521ea2bf2f93f28f6d7e875d55372c689f - Sigstore transparency entry: 842547403
- Sigstore integration time:
-
Permalink:
96hoshi/nigiri@d6cdda0fdb0b90e1a116c7af054cb6ed4cdf5577 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/96hoshi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@d6cdda0fdb0b90e1a116c7af054cb6ed4cdf5577 -
Trigger Event:
release
-
Statement type: