Skip to main content

Simple osm routing engine.

Project description

routor

PyPI GitHub Workflow Status (main) Coveralls github branch PyPI - Python Version PyPI - License

Simple routing engine for OpenStreetMaps with easy to customize profiles/weight-functions.

Requirements

  • Python 3.6.1 or newer

Installation

pip install routor

Usage

CLI

The CLI offers multiple commands, use routor --help to find out more.

Download map

Downloads a compatible map from OSM, eg.

routor download "Bristol, England" ./bristol.graphml

Calculate route

Determine the optimal route between two points using the given weight function and print the route as JSON to stdout.

routor route -- ./bristol.graphml  "51.47967237816338,-2.6174926757812496" "51.45422084861252,-2.564105987548828" "routor.weights.length"

Web API

Configuration

The configuration is either read from a .env file or the environment. Before you are able to run the server, you have to set the variables mentioned in routor/api/config.py.

Run the API

The api is served using uvicorn. To start the server run

uvicorn routor.api:app

The API will be available at http://127.0.0.1:8000 and the docs at http://127.0.0.1:8000/docs.

Register a new weight function

Existing weight functions are defined in routor/weights.py. To add a new weight functon, you have to create a new project and add routor as dependency. Create a new file, eg. main.py and add the following content, which will become the entrypoint for uvicorn.

# main.py
from typing import Optional

from routor.api.main import app  # noqa
from routor.weights import register
from routor import models


def my_weight_func(prev_edge: Optional[models.Edge], edge: models.Edge) -> float:
    ...
    return ...


register(my_weight_func, "weight_func")

Start the server with uvicorn main:app and the weight function will be available as weight_func when calling the api.

As library

You can also use the engine as a library. To calculate a route from A to B you can do

from routor.engine import Engine
from routor import models, weights

...
map_path = Path(...)
engine = Engine(map_path)

origin = models.Location(latitude=51.47967237816338, longitude=-2.6174926757812496)
destination = models.Location(latitude=51.45422084861252, longitude=-2.564105987548828)

route = engine.route(origin, destination, weights.length)  # shortest distance

Available weight-functions

"length" / routor.weights.length

Calculates the shortest path from A to B, only the length of an edge is taken into account.

"travel_time" / routor.weight.travel_time

Calculates the fastest route based on travel time.

Development

This project uses poetry for packaging and managing all dependencies and pre-commit to run flake8, isort, mypy and black.

Additionally, pdbpp and better-exceptions are installed to provide a better debugging experience. To enable better-exceptions you have to run export BETTER_EXCEPTIONS=1 in your current session/terminal.

Clone this repository and run

poetry install
poetry run pre-commit install

to create a virtual enviroment containing all dependencies. Afterwards, You can run the test suite using

poetry run pytest

This repository follows the Conventional Commits style.

Cookiecutter template

This project was created using cruft and the cookiecutter-pyproject template. In order to update this repository to the latest template version run

cruft update

in the root of this repository.

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

routor-0.3.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

routor-0.3.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file routor-0.3.0.tar.gz.

File metadata

  • Download URL: routor-0.3.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for routor-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a1fc84a396dd7756222fbbbef904cef5c1a3defb42e818e2cf91eeac5b453efb
MD5 8a3b91d4a40bc68c729ff15fe3b81b63
BLAKE2b-256 9e67407f3fb48cdc29040b0c0abec440a081d7d5938a3bf9ad84c0ccdf0d84c9

See more details on using hashes here.

File details

Details for the file routor-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: routor-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for routor-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4351b47198c786dbe91c3cbe25be9870878f5cdb0a1ce612047817aef9ec75f1
MD5 5861e893e0c19afe240cabc31c1dd713
BLAKE2b-256 7a8881282c309d277989adecc98c4983d012c5902b9c6bd4ec1b6253549df6cf

See more details on using hashes here.

Supported by

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