Python bindings for the osrm-backend project (actively maintained fork)
Project description
py-osrm-revival
py-osrm-revival is an actively maintained continuation of py-osrm, providing Python bindings to osrm-backend using nanobind.
This project was forked from gis-ops/py-osrm which is now archived and unmaintained. Development continues here.
This package binds to OSRM v6.0.0 backend and includes preprocessing functionality.
Supported Platforms
| Platform | Arch |
|---|---|
| Linux | x86_64 |
| MacOS | x86_64 |
| Windows | x86_64 |
Installation
py-osrm-revival is supported on CPython 3.9+.
Install from PyPI:
pip install py-osrm-revival
Or install from GitHub Releases:
Download the appropriate wheel for your platform from Releases:
pip install https://github.com/nick-fournier/py-osrm/releases/download/v0.1.0/py_osrm_revival-0.1.0-cp39-abi3-linux_x86_64.whl
Development install (requires compilation, ~5-10 min):
pip install git+https://github.com/nick-fournier/py-osrm.git@revival
From source:
git clone https://github.com/nick-fournier/py-osrm.git
cd py-osrm
git checkout revival
pip install .
Note: Development and source installations require a C++ compiler (GCC/Clang) and CMake.
Quick Start
import osrm
# Load preprocessed data
py_osrm = osrm.OSRM("path/to/data.osrm")
# Calculate route - pass coordinates directly!
result = py_osrm.Route([(7.41337, 43.72956), (7.41546, 43.73077)])
print(result["routes"][0]["distance"]) # Distance in meters
Usage
Routing Services
Route - Calculate routes between coordinates:
result = py_osrm.Route(
coordinates=[(7.41337, 43.72956), (7.41546, 43.73077)],
steps=True,
geometries="geojson",
annotations=["speed", "distance"]
)
Table - Calculate distance/duration matrices:
result = py_osrm.Table(
coordinates=[(7.41337, 43.72956), (7.41546, 43.73077), (7.41862, 43.73216)],
annotations=["distance", "duration"]
)
# Access via result["distances"] and result["durations"]
Nearest - Find nearest road segment:
result = py_osrm.Nearest(
coordinates=[(7.41337, 43.72956)],
number=3
)
See the documentation for Trip, Match, and Tile services.
Bulk Processing (Concurrent)
Process multiple routes in parallel using ThreadPoolExecutor for significant speedup:
import polars as pl
import osrm
# Initialize OSRM instance
py_osrm = osrm.OSRM("path/to/data.osrm")
# Create DataFrame with origin-destination pairs
df = pl.DataFrame({
"origin_lon": [7.41337, 7.41862, 7.42150],
"origin_lat": [43.72956, 43.73216, 43.73400],
"dest_lon": [7.41546, 7.42000, 7.42300],
"dest_lat": [43.73077, 43.73300, 43.73500]
})
# Process all routes concurrently (releases GIL for true parallelism)
results = osrm.bulk_route(py_osrm, df, steps=True, geometries="geojson")
# Results DataFrame includes: distance, duration, geometry, success, error
print(results.select(["distance", "duration", "success"]))
Installation with bulk processing support:
pip install py-osrm-revival[bulk] # Polars only
pip install py-osrm-revival[bulk-progress] # Polars + tqdm progress bar
Key features:
- True parallel execution (GIL released in C++)
- Works with Polars DataFrames or dict-of-lists
- Per-row parameter customization
- Automatic error handling with
fail_fastoption - Progress tracking with
show_progress=True - Typically 3-4x faster than sequential processing on 4+ cores
Preprocessing
Before routing, you must preprocess OpenStreetMap data. Built-in profiles include car, bicycle, and foot:
CH (Contraction Hierarchies) - Fastest queries:
import osrm
# Extract road network from OSM data
osrm.extract("data.osm.pbf", profile="car", output_path="data")
# Build routing graph (CH)
osrm.contract("data")
# Ready to use
py_osrm = osrm.OSRM("data.osrm")
Using a custom profile:
osrm.extract("data.osm.pbf", profile="/path/to/custom.lua", output_path="data")
CLI usage:
python -m osrm extract data.osm.pbf --profile car
python -m osrm contract data
For MLD (Multi-Level Dijkstra) on larger datasets, see preprocessing documentation.
Advanced Usage
Legacy Parameter Objects
Alternative usage with parameter objects (click to expand)
Parameter objects are still supported for backwards compatibility:
# Create parameter object
route_params = osrm.RouteParameters(
coordinates=[(7.41337, 43.72956), (7.41546, 43.73077)]
)
# Pass to Route method
result = py_osrm.Route(route_params)
This pattern is useful when constructing parameters programmatically or reusing them across multiple requests. However, the direct keyword argument pattern shown above is now recommended for most use cases.
Documentation
Acknowledgments
This project is a continuation of gis-ops/py-osrm. Thanks to the original authors for their foundational work.
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 Distributions
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 py_osrm_revival-0.1.0-cp310-cp310-macosx_15_0_arm64.whl.
File metadata
- Download URL: py_osrm_revival-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
- Upload date:
- Size: 20.9 MB
- Tags: CPython 3.10, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c2d3c65e4a8aaf3853f7d5298904d160e54b4377890dae04392b4f21ec54f65
|
|
| MD5 |
0cde13e29a15b95ba00405535444eb1c
|
|
| BLAKE2b-256 |
592d02c79ddc108bee057a67b265a8c6901223c0fdcd7216abf345ca405f0704
|
Provenance
The following attestation bundles were made for py_osrm_revival-0.1.0-cp310-cp310-macosx_15_0_arm64.whl:
Publisher:
release.yml on nick-fournier/py-osrm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_osrm_revival-0.1.0-cp310-cp310-macosx_15_0_arm64.whl -
Subject digest:
4c2d3c65e4a8aaf3853f7d5298904d160e54b4377890dae04392b4f21ec54f65 - Sigstore transparency entry: 1438020907
- Sigstore integration time:
-
Permalink:
nick-fournier/py-osrm@3029092aa785e86e44640c8435e333787f17b15e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/nick-fournier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3029092aa785e86e44640c8435e333787f17b15e -
Trigger Event:
push
-
Statement type: