Skip to main content

pyroutelib3

GitHub | Documentation | Issue Tracker | PyPI

Simple routing over OSM data.

pyroutelib3 is a Python library for simple routing over OpenStreetMap data.

import pyroutelib3

live_graph = pyroutelib3.osm.LiveGraph(pyroutelib3.osm.CarProfile())

start_node = live_graph.find_nearest_node((52.23201, 21.00737))
end_node = live_graph.find_nearest_node((52.24158, 21.02807))

route = pyroutelib3.find_route_without_turn_around(live_graph, start_node.id, end_node.id)
route_lat_lons = [live_graph.get_node(node).position for node in route]

The example above uses osm.LiveGraph, which automatically downloads OpenStreetMap data in tiles and caches them on your disk. It is much more wise to download the data beforehand from a service like Geofabrik OSM data extracts:

import pyroutelib3

with open("mazowieckie-latest.osm.pbf", "rb") as f:
    graph = pyroutelib3.osm.Graph.from_file(pyroutelib3.osm.CarProfile(), f)

start_node = graph.find_nearest_node((52.23201, 21.00737))
end_node = graph.find_nearest_node((52.24158, 21.02807))

route = pyroutelib3.find_route_without_turn_around(graph, start_node, end_node)
route_lat_lons = [graph.get_node(node).position for node in route]

pyroutelib3 not only is able to parse OpenStreetMap data into a graph (see the osm module), but also contains generic implementations of the A* path-finding algorithm (find_route and find_route_without_turn_around functions) and the k-d tree data structure (KDTree class).

This library was designed with extensibility in mind, and most components can be swapped for completely custom ones through the usage of well-defined protocols. As an example, a nx.GraphAdaptor is provided to use networkx graphs with pyroutelib3's functionality.

Installation

pip install --upgrade pyroutelib3

pyroutelib3 uses semantic versioning. Always specify dependencies on this library with a constraint on the major revision, e.g. pyroutelib3 ~= 2.0.0.

Note that version 1 of this library is incompatible with version 2.

Features

  • Generic A* algorithm implementation (find_route and find_route_without_turn_around functions)
  • Generic graph data structure (SimpleGraph class)
  • Generic k-d data structure (KDTree class)
  • Extensibility through usage of well-defined protocols (protocols module)
    • networkx compatibility (nx.GraphAdaptor and nx.ExternalGraphAdaptor classes)
  • OSM XML and OSM PBF file parsing (osm.reader.read_features function)
  • Converting OpenStreetMap data into a usable graph (osm.Graph class)
    • High customizability of the process through the usage of different profiles.
    • Expressing way preferences through the usage of penalties for unpreferred tags
    • Respecting access restrictions on ways
    • Support for turn restrictions, including restriction:TRANSPORT and exempt tags
    • Downloading data on-the-fly (osm.LiveGraph class)

License

pyroutelib3 is distributed under GNU GPL v3 (or any later version).

© Copyright 2024 Mikołaj Kuranowski

pyroutelib3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

pyroutelib3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with pyroutelib3. If not, see http://www.gnu.org/licenses/.

Metadata

Release files for pyroutelib3 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyroutelib3 2.0.0
File Size Uploaded Provenance
pyroutelib3-2.0.0.tar.gz 63.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyroutelib3 2.0.0
File Interpreter ABI Platform
pyroutelib3-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 129.1 kB

Release files / pyroutelib3-2.0.0.tar.gz

Download URL pyroutelib3-2.0.0.tar.gz
Size 63.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0fb7eec4cf2893e2f75474c3ad66d900b457a03e8aa45d7147d7aa4f169a4c63
BLAKE2b-256 checksum
How to use checksums
7a877dab1cd2d661b5284c972f4108727732a50264ce626baecef5a634619ca3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / pyroutelib3-2.0.0-py3-none-any.whl

Download URL pyroutelib3-2.0.0-py3-none-any.whl
Size 66.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5644c9445de81c5c787b5c97ae446799939b5143e504976dea19e31bcb5061d3
BLAKE2b-256 checksum
How to use checksums
5e4690c0bbdc73f65b9ed3399ff44b22ff5ffee6f67c2a1f9986769897587ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Security for pyroutelib3 2.0.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page