Python client for requests to openrouteservice API services
Project description
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 CPython 3.7, 3.8 and 3.9, and PyPy3.
For setting up a testing environment, install requirements-dev.txt:
pip install -r requirements-dev.txt
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:
nosetests -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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file openrouteservice-2.3.3.tar.gz
.
File metadata
- Download URL: openrouteservice-2.3.3.tar.gz
- Upload date:
- Size: 29.1 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3696e0428533cf6bbcb9586c3bcfca7b5e7aaa269650ff16a862a7f61b857f4a |
|
MD5 | f71e701ddb940b2f60500e4304c28c4e |
|
BLAKE2b-256 | c7c22a9784750f244d6f2ae982f7e2862383af4c6d8d9e9ca793603500d04d16 |
File details
Details for the file openrouteservice-2.3.3-py3-none-any.whl
.
File metadata
- Download URL: openrouteservice-2.3.3-py3-none-any.whl
- Upload date:
- Size: 33.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a84fe298b1de7a4fb1d8aa19798687f4f66fe212e5206667c703ca2c7e5de0ce |
|
MD5 | f5875cd1f7fae8460ed7ea3a8735fbbf |
|
BLAKE2b-256 | 671ae6944e4cfd7c5386b15e4b4056084b3c8c676aca0a215d8b507a6cbc1263 |