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 Distribution

osrm_bindings-26.7.2.tar.gz (10.7 MB view details)

Uploaded Source

Built Distributions

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

osrm_bindings-26.7.2-cp312-abi3-manylinux_2_28_x86_64.whl (19.5 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.12+macOS 15.0+ x86-64

osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.12+macOS 15.0+ ARM64

File details

Details for the file osrm_bindings-26.7.2.tar.gz.

File metadata

  • Download URL: osrm_bindings-26.7.2.tar.gz
  • Upload date:
  • Size: 10.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for osrm_bindings-26.7.2.tar.gz
Algorithm Hash digest
SHA256 6e33c19b23625e985e1b6ec9a21b0d3a886d2de173c8c2b6a9d73b9e8b71a258
MD5 2a417e73e0e4a887e59abd4f7c8922ac
BLAKE2b-256 bf5cff6a4aff3c95835c1da5e4c987a354564d29a5e8152f8481318b064c214a

See more details on using hashes here.

Provenance

The following attestation bundles were made for osrm_bindings-26.7.2.tar.gz:

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.

File details

Details for the file osrm_bindings-26.7.2-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for osrm_bindings-26.7.2-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 595d02f762423be5092652f0021a3450eba91b4cf0bea78b7b01d923bfaa2e87
MD5 50544417de8bbe7376da43a9d9672612
BLAKE2b-256 75d546a017141ea5131d642a43593c0c04efd02d492f143de54b15a890c0da2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for osrm_bindings-26.7.2-cp312-abi3-manylinux_2_28_x86_64.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.

File details

Details for the file osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e2a3d348b3a1c5e7bec07ece2d25c375d538b124b4ae083e1e809c0207d32e63
MD5 6370c0b48cd09480c773b4fb8db7ccac
BLAKE2b-256 72dcb662504d285084e33bd0db782da6b1a85ef9c63898494964f14f0c21b9bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_x86_64.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.

File details

Details for the file osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 612f99b9e7fd05bb8297d6197261fc436da122f503da52cc53051d47d84a9913
MD5 e47373047a4ea71ca75a17cd36d88e65
BLAKE2b-256 c5184f0824678ba417ab8760ec0884315b7128f538d47348f85430f1e514caca

See more details on using hashes here.

Provenance

The following attestation bundles were made for osrm_bindings-26.7.2-cp312-abi3-macosx_15_0_arm64.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