Package: openrouteservice
QuickstartDescriptionThe openrouteservice library gives you painless access to theopenrouteservice(ORS) routing API’s.
It performs requests against our API’s fordirectionsisochronesmatrix routing calculationsplaceselevationPelias geocodingPelias reverse geocodingPelias structured geocodingPelias autocompleteOptimizationFor further details, please visit:homepageORS API documentationopenrouteservice-py documentationWe also have a repo with a few useful exampleshere.For support, please ask ourforum.By using this library, you agree to the ORSterms and conditions.Requirementsopenrouteservice-py is tested against CPython 3.7, 3.8 and 3.9, and PyPy3.For setting up a testing environment, installrequirements-dev.txt:pip install -r requirements-dev.txtInstallationTo install from PyPI, simply use pip:pip install openrouteserviceTo install the latest and greatest from source:pip install git+git://github.com/GIScience/openrouteservice-py@developmentTestingIf you want to run the unit tests, seeRequirements.cdto the library directory and run:nosetests -v-vflag for verbose output (recommended).UsageFor an interactive Jupyter notebook have a look onmybinder.org.Basic exampleimportopenrouteservicecoords=((8.34234,48.23424),(8.34423,48.26424))client=openrouteservice.Client(key='')# Specify your personal API keyroutes=client.directions(coords)print(routes)For convenience, all request performing module methods are wrapped inside theclientclass. 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, isimportopenrouteservicefromopenrouteservice.directionsimportdirectionscoords=((8.34234,48.23424),(8.34423,48.26424))client=openrouteservice.Client(key='')# Specify your personal API keyroutes=directions(client,coords)# Now it shows you all arguments for .directionsOptimize routeIf you want to optimize the order of multiple waypoints in a simpleTraveling Salesman Problem,
you can pass aoptimize_waypointsparameter:importopenrouteservicecoords=((8.34234,48.23424),(8.34423,48.26424),(8.34523,48.24424),(8.41423,48.21424))client=openrouteservice.Client(key='')# Specify your personal API keyroutes=client.directions(coords,profile='cycling-regular',optimize_waypoints=True)print(routes)Decode PolylineBy default, the directions API returnsencoded polylines.
To decode to adict, which is a GeoJSON geometry object, simply doimportopenrouteservicefromopenrouteserviceimportconvertcoords=((8.34234,48.23424),(8.34423,48.26424))client=openrouteservice.Client(key='')# Specify your personal API key# decode_polyline needs the geometry onlygeometry=client.directions(coords)['routes'][0]['geometry']decoded=convert.decode_polyline(geometry)print(decoded)Dry runAlthough errors in query creation should be handled quite decently, you can do a dry run to print the request and its parameters:importopenrouteservicecoords=((8.34234,48.23424),(8.34423,48.26424))client=openrouteservice.Client()client.directions(coords,dry_run='true')Local ORS instanceIf you’re hosting your own ORS instance, you can alter thebase_urlparameter to fit your own:importopenrouteservicecoords=((8.34234,48.23424),(8.34423,48.26424))# key can be omitted for local hostclient=openrouteservice.Client(base_url='http://localhost/ors')# Only works if you didn't change the ORS endpoints manuallyroutes=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'})SupportFor general support and questions, contact ourforum.For issues/bugs/enhancement suggestions, please usehttps://github.com/GIScience/openrouteservice-py/issues.AcknowledgementsThis library is based on the very elegant codebase fromgooglemaps.