Compute a route with Thinwrap (Python)
Compute a route via the Thinwrap Routing facade in Python — one call shape for Mapbox, Google, HERE, ESRI, TomTom and OSRM.
1. Install
pip install thinwrap-location2. Send the call
import os
from thinwrap.location import Routing, RoutingOptions, MapboxConfig, LatLng, TravelMode, ConnectorError
r = Routing(MapboxConfig(access_token=os.environ["MAPBOX_ACCESS_TOKEN"]))
try:
res = r.route(RoutingOptions(
waypoints=[LatLng(52.5200, 13.4050), LatLng(52.5163, 13.3777)],
travel_mode=TravelMode.DRIVING,
))
# res.polyline is the encoded geometry; res.raw keeps the vendor body verbatim.
print(res.total_distance_meters, res.total_duration_seconds)
except ConnectorError as err:
print(f"{err.provider_code.value}: {err.provider_message}")
Same code works for all supported providers — just change the provider ID.