Closed samuelleach closed 3 years ago
Yeah it's been a while since I created this. Could indeed be possible that the API has changed. Main reason why I haven't kept this up to date is indeed time :)
Also meanwhile Mapbox brought out their own Python wrapper, which is probably the best source in case you want to write a proper OSRM wrapper: https://github.com/mapbox/mapbox-sdk-py
Let me know in case you end up writing something, then I will point to you in the Readme.
That's a good point - the mapbox-sdk looks like a good example to copy / learn from. As I guess you know, their SDK queries the Mapbox APIs, not OSRM directly.
Ok I'll keep you posted on how it goes.
Yeah I think the endpoint of the Mapbox Directions API and the OSRM API are the same. Only the base url should be different.
I am looking to do the same and was about to start tweaking to make a few of the function work with v5. How far have you got since this tread got going, samuelleach? Wouldn't want to duplicate work....
Hi,
I took code updated to the v5 api i had on other projects and i modified some of the functions of this package (fork is on https://github.com/mthh/python-osrm if you want to take a look, there is also some tests included) I do not know if it fits in with what you expect for this package but I will be glad to fill a PR if you are interested! (as it, or with changes you might request, or after working a bit on it)
What it currently do:
What I am planning to do:
Quick example :
In [1]: import osrm
In [2]: osrm.RequestConfig
Out[2]: http://localhost:5000/*/v1/driving
In [3]: osrm.RequestConfig.host = "router.project-osrm.org"
In [4]: osrm.RequestConfig
Out[4]: router.project-osrm.org/*/v1/driving
In [5]: osrm.nearest((14.4458221,35.8868013))
Out[5]:
{'code': 'Ok',
'waypoints': [{'name': "Triq Ta' Qassati",
'location': [14.445674, 35.886404],
'hint': 'hV7egfN-OIgG8wgBBwAAAEQAAAAIBAAAEwEAABDrdQEqpqwCbrcAAGps3ABElSMC_mzcANGWIwILAAEBfDhq3w==',
'distance': 46.12695}]}
In [6]: osrm.simple_route((14.4458221,35.8868013), (14.4296317, 35.9152936), overview="full", output="route", geometry="wkt")
Out[6]:
[{'legs': [{'summary': '',
'steps': [],
'duration': 400.3,
'distance': 4895.7}],
'geometry': 'LINESTRING (14.44567 35.8864,14.44505 35.88656,14.44454 35.8866,14.44404 35.88653,14.44371 35.88656,14.44248 35.88685,14.44262 35.88804,14.44263 35.88841,14.44262 35.88847,14.44254 35.88896,14.44251 35.8893,14.44241 35.88952,14.44215 35.88955,14.44149 35.88944,14.44129 35.88941,14.4411 35.88939,14.44036
...
In [7]: MyConfig = osrm.RequestConfig('myOsrmInstance:5000/v1/biking')
In [8]: MyConfig
Out[8]: myOsrmInstance:5000/*/v1/biking
In [9]: MyConfig.profile
Out[9]: 'biking'
In [10]: osrm.nearest((14.4458221,35.8868013), url_config=MyConfig)
Traceback (most recent call last):
(...)
ValueError: Error while contacting OSRM instance :
<urlopen error [Errno -2] Name or service not known>
Sorry for the long post, Cheers!
Respect! I will try it out
I came across these bindings this weekend. I'd like to be able to access the OSRM via Python.
It seems like the OSRM API and response format has changed since you wrote this. The latest version v5 has docs here:
For info, the docs for v5 API are here: https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md
I'm considering rewriting these bindings (using a cookiecutter python package), using your work as a starting point, and keeping an eye on the node-osrm, which seems to be Mapbox's main effort to provide bindings to OSRM.
I just wondered whether you could provide any pointers here. Is there some reason (apart from time) why you have not pursued the python bindings recently?