Skip to main content
Build status Codecov coverage Documentation Status PyPI version MyBinder

Quickstart

Description

The openrouteservice library gives you painless access to the openrouteservice (ORS) routing API’s. It performs requests against our API’s for

For further details, please visit:

We also have a repo with a few useful examples here.

For support, please ask our forum.

By using this library, you agree to the ORS terms and conditions.

Requirements

openrouteservice-py is tested against Python 3.6, 3.7, 3.8 and 3.9, and PyPy3.6 and PyPy3.7.

For setting up a testing environment, install poetry first.

For Linux and osx:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

For windows:

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -

Then create a venv and install the dependencies with poetry:

python -m venv .venv && source .venv/bin/activate
poetry install -vv

Installation

To install from PyPI, simply use pip:

pip install openrouteservice

To install the latest and greatest from source:

pip install git+git://github.com/GIScience/openrouteservice-py@development

Testing

If you want to run the unit tests, see Requirements. cd to the library directory and run:

pytest -v

-v flag for verbose output (recommended).

Usage

For an interactive Jupyter notebook have a look on mybinder.org.

Basic example

import openrouteservice

coords = ((8.34234,48.23424),(8.34423,48.26424))

client = openrouteservice.Client(key='') # Specify your personal API key
routes = client.directions(coords)

print(routes)

For convenience, all request performing module methods are wrapped inside the client class. This has the disadvantage, that your IDE can’t auto-show all positional and optional arguments for the different methods. And there are a lot!

The slightly more verbose alternative, preserving your IDE’s smart functions, is

import openrouteservice
from openrouteservice.directions import directions

    coords = ((8.34234,48.23424),(8.34423,48.26424))

    client = openrouteservice.Client(key='') # Specify your personal API key
    routes = directions(client, coords) # Now it shows you all arguments for .directions

Optimize route

If you want to optimize the order of multiple waypoints in a simple Traveling Salesman Problem, you can pass a optimize_waypoints parameter:

import openrouteservice

coords = ((8.34234,48.23424),(8.34423,48.26424), (8.34523,48.24424), (8.41423,48.21424))

client = openrouteservice.Client(key='') # Specify your personal API key
routes = client.directions(coords, profile='cycling-regular', optimize_waypoints=True)

print(routes)

Decode Polyline

By default, the directions API returns encoded polylines. To decode to a dict, which is a GeoJSON geometry object, simply do

import openrouteservice
from openrouteservice import convert

coords = ((8.34234,48.23424),(8.34423,48.26424))

client = openrouteservice.Client(key='') # Specify your personal API key

# decode_polyline needs the geometry only
geometry = client.directions(coords)['routes'][0]['geometry']

decoded = convert.decode_polyline(geometry)

print(decoded)

Dry run

Although errors in query creation should be handled quite decently, you can do a dry run to print the request and its parameters:

import openrouteservice

coords = ((8.34234,48.23424),(8.34423,48.26424))

client = openrouteservice.Client()
client.directions(coords, dry_run='true')

Local ORS instance

If you’re hosting your own ORS instance, you can alter the base_url parameter to fit your own:

import openrouteservice

coords = ((8.34234,48.23424),(8.34423,48.26424))

# key can be omitted for local host
client = openrouteservice.Client(base_url='http://localhost/ors')

# Only works if you didn't change the ORS endpoints manually
routes = client.directions(coords)

# If you did change the ORS endpoints for some reason
# you'll have to pass url and required parameters explicitly:
routes = client.request(
  url='/new_url',
  post_json={
      'coordinates': coords,
      'profile': 'driving-car',
      'format': 'geojson'
  })

Support

For general support and questions, contact our forum.

For issues/bugs/enhancement suggestions, please use https://github.com/GIScience/openrouteservice-py/issues.

Acknowledgements

This library is based on the very elegant codebase from googlemaps.

Metadata

Release files for openrouteservice 2.4.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 openrouteservice 2.4.0
File Size Uploaded Provenance Actions
openrouteservice-2.4.0.tar.gz 25.4 kB Without provenance Details for openrouteservice-2.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 60.0 kB

Release files / openrouteservice-2.4.0.tar.gz

Download URL openrouteservice-2.4.0.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
39df29491b18714b84de7131e0e59d222393a6dfb2df4aab1478a20dc691ff47
BLAKE2b-256 checksum
How to use checksums
216074609843f141db962a7f11ead94446ec08993ba6688f3e601888bea793e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.2 CPython/3.14.10 Linux/7.0.0-1020-azure

Release files / openrouteservice-2.4.0-py3-none-any.whl

Download URL openrouteservice-2.4.0-py3-none-any.whl
Size 34.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6254559e8597d2ac54d6f9bcd03c0b210c9fafc0e04e961f56846abf559b5510
BLAKE2b-256 checksum
How to use checksums
6589ea5c9a7482d7ac67cd06bb7dc7e8dcc7d58483f4a3c03f90ecebf9ed41cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.2 CPython/3.14.10 Linux/7.0.0-1020-azure

Security for openrouteservice 2.4.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