Skip to main content

Python bindings for the osrm-backend project

Project description

osrm-bindings

Python bindings for osrm-backend using nanobind.

PyPI

pip install osrm-bindings

[!NOTE] On PyPI we only distribute abi3 wheels for each platform, i.e. one needs at least Python 3.12 to install the wheels. Of course it'll fall back to attempt an installation from source.

Platform Arch
Linux x86_64
MacOS aarch64
MacOS arm64
Windows x86_64

From Source

osrm-bindings requires CPython 3.10+ and can be installed from source (e.g. from an sdist on PyPI) by running the following command in the repository root:

pip install .

The Python bindings are built alongside the OSRM C++ libraries. The version of the bindings matches the version of osrm-backend.

System dependencies

A source/sdist build compiles the full OSRM C++ library, so the usual C++ toolchain (CMake ≥ 3.18, a C++20 compiler, Git) plus OSRM's native dependencies must be available. Also a development Python installation has to be in the PATH.

Debian / Ubuntu

sudo apt-get install -y \
    cmake g++ git pkg-config \
    libboost-all-dev libbz2-dev liblua5.4-dev \
    libtbb-dev libxml2-dev libzip-dev

Fedora / RHEL / Rocky / AlmaLinux

sudo dnf install -y \
    cmake gcc-c++ git pkgconf-pkg-config \
    boost-devel bzip2-devel lua-devel \
    tbb-devel libxml2-devel libzip-devel

macOS (Homebrew)

brew install cmake lua tbb boost@1.90
brew link boost@1.90

Windows (vcpkg + MSVC)

Windows builds use vcpkg to provide OSRM's C++ dependencies and require a recent MSVC toolset (Visual Studio 2022 or later).

Example steps (PowerShell / Developer Command Prompt):

# Clone & bootstrap vcpkg
git clone https://github.com/microsoft/vcpkg.git C:\vcpkg
cd C:\vcpkg
.\bootstrap-vcpkg.bat

cmake --preset release
cmake --build buildß

If installing from a pip sdist, ensure CMake is configured to use the same vcpkg toolchain file (pass the toolchain via CMake args when building the wheel or use the same environment when running pip install).

Example

The following example will showcase the process of calculating routes between two coordinates.

First, import the osrm library, and instantiate an instance of OSRM:

import osrm

# Instantiate osrm_py instance
osrm_py = osrm.OSRM("./test/data/ch/monaco.osrm")

Then, declare RouteParameters, and then pass it into the osrm_py instance:

# Declare Route Parameters
route_params = osrm.RouteParameters(
    coordinates = [(7.41337, 43.72956), (7.41546, 43.73077)]
)

# Pass it into the osrm_py instance
res = osrm_py.Route(route_params)

# Print out result output
print(res["waypoints"])
print(res["routes"])

Type Stubs

The file src/python/osrm/osrm_ext.pyi contains auto-generated type stubs for the C++ extension module. These are used by IDEs for autocompletion and by documentation tools without compiling the extension.

After changing C++ bindings, rebuild the project to regenerate the stubs:

pip install -e .

Then commit the updated .pyi file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osrm_bindings-26.7.3.post1.dev0-cp312-abi3-win_amd64.whl (13.1 MB view details)

Uploaded CPython 3.12+Windows x86-64

File details

Details for the file osrm_bindings-26.7.3.post1.dev0-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for osrm_bindings-26.7.3.post1.dev0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 81c62048741721db1fae4963d178e3d75d28fcaaa4577e5aecf196fa2442c6b2
MD5 76339a3eec9e3cc2c6c6ac1bececc71a
BLAKE2b-256 312092907ca9fb0192d25335075a3bcea64fc0fd8af4ac78c99417d76d40cb8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for osrm_bindings-26.7.3.post1.dev0-cp312-abi3-win_amd64.whl:

Publisher: release-monthly.yml on Project-OSRM/osrm-backend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page