Configure the OSRM host and profile using RequestConfig
masterYou can change the target OSRM server or the profile (e.g., driving, biking) in two ways:
- Global Change: Modify
osrm.RequestConfig.hostto change the default URL for all subsequent requests. - Instance-based Change: Create a new
osrm.RequestConfiginstance. This is useful for switching between different URLs or using basic authentication. Pass this instance to theurl_configparameter of API functions.
import osrm
# Method 1: Change global default host
osrm.RequestConfig.host = "router.project-osrm.org"
# Method 2: Use a specific config instance for a single call
# Supports basic authentication: basic_auth=("user", "pass")
MyConfig = osrm.RequestConfig("localhost:9999/v1/biking", basic_auth=("user", "pass"))
MyConfig.profile = "driving"
# Use the config in a function call
result = osrm.simple_route(p1, p2, url_config=MyConfig)