Skip to main content

Python client for requests to openrouteservice API services

Project description

Build status Documentation Status

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 requires:

  • Python >= 2.7, 3.4, 3.5, 3.6

  • requests library

unit testing requires additionally the following Python libraries:

  • nose

  • responses

  • mock

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

For conda users, you can install using setuptools (required Python package):

git clone https://github.com/GIScience/openrouteservice-py
python setup.py install

This command group will install the library to your global environment. Also works in virtual environments.

Testing

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

nosetests -v

-v flag for verbose output (recommended).

Usage

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

Decode Polyline

By default, the directions API returns encoded polylines. To decode to a dict, which is GeoJSON-ready, 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(key='') # Specify your personal API key
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(key='',
                                 base_url='https://foo/bar')

# url is the extension for your endpoint, no trailing slashes!
# params has to be passed explicitly, refer to API reference for details
routes = client.request(url='/directions',
                        params={'coordinates': coords,
                                'profile': 'driving-hgv'
                               }
                        )

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.

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

openrouteservice-1.0.tar.gz (30.8 kB view details)

Uploaded Source

Built Distributions

openrouteservice-1.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

openrouteservice-1.0-py2.py3-none-any.whl (33.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file openrouteservice-1.0.tar.gz.

File metadata

  • Download URL: openrouteservice-1.0.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for openrouteservice-1.0.tar.gz
Algorithm Hash digest
SHA256 810e3c817aca680dcc8252b5ad3da18bc6361df304bb76bde0362566a903d453
MD5 d17195fa1488cfea39cae2fca1483b10
BLAKE2b-256 845db56100badf2a75babda71218969edd410832f83318a16ace5c6eb2194742

See more details on using hashes here.

File details

Details for the file openrouteservice-1.0-py3-none-any.whl.

File metadata

  • Download URL: openrouteservice-1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for openrouteservice-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b70c2ba54d75e1fd350d0d99b64bc74fab2504d6518a8fdd2692c56e8456ac8f
MD5 34614f2c04080c56faba2a230ca44939
BLAKE2b-256 fa1609e4ef9fde3beefcfa782a9e9ea3793381a7c9ede1a6bbf4e1d606e4a260

See more details on using hashes here.

File details

Details for the file openrouteservice-1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: openrouteservice-1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for openrouteservice-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c45755379a0df6e96b1c303ff9840f42bfbb7ff381cfcb744a7a28b9aa388739
MD5 371b9819171221ee4cb98c3d48847d9b
BLAKE2b-256 0f91801e14f3a27e9ceee814e5ca1523f7a1663e2495ed59a120fe9dc3419dd2

See more details on using hashes here.

Supported by

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