Package: osm-helper
OSM-HELPER: A fast way to get the ETA (Estimated Time of Arrival)  🗺️ 🚀Do you have multiple python projects for Delivery 🛵, Ride-hailing 🚗 or any logistics service, and each time you need to build theget_etafunction from scratch ?This simple package is your right way! 🚀🚀osm-hepleris a pretty simple package for making the process of getting eta for a number of locations to be the easiest part in your project (just two lines of code).The package built on top ofOSRM(Open Source Routing Machine) project. :world_map:We can assume it as a python wrapper on top of thetableservice api of theOSRMproject.Installationpip install osm-helperFeatures1-A default parameters(that make the performance better) are initialized and they are configurable.2-Cachingthe results.3-Load balancingbetween more than oneosrminstance.4-Fault tolerance: if one of theosrminstances is down, it will search for another (this will be done by default in the package).ExamplesSimple ExampleAfter installing the lib you can test it by the following:fromosm_helper.osm_apiimportOSMdefsimple_example():locations=[("25.22386255613285","55.28397838209264"),("25.356481138224012","55.404779909052124"),]# Create a pretty simple OSM instanceosm_api=OSM()# Get the timesresult=osm_api.osm_matrix(locations,[0],# Source location index[1],# Destination location index)returnresultprint(simple_example())By running the code (you will got the following result, the value may be changed with a small changes depending on the OSRM instance you are using):{'duration': [[1128.8]]}Caching and Load balancing ExampleYou need to install redis and set its config in the .yaml config file:REDIS_HOST:
 127.0.0.1

REDIS_PORT:
 6379

REDIS_EXPIRATION_TIME: # Optional
 43200 

REDIS_ASYNC_CACHE: # Optional
 FalseThen you can:fromosm_helper.locationsimportgenerate_random_locationsfromosm_helper.osm_apiimportOSM# Generate 10 random locationslocations=generate_random_locations(("30.222676136092296","31.455316886214952"),number=10)# Create an OSM instanceosm_api=OSM(load_balance=True,cache_results=True,with_distance=True)# Get the timesresult=osm_api.osm_matrix(locations,[iforiinrange(len(locations)//2)],[iforiinrange(len(locations)//2,len(locations))],request_id="123")print(result)OSM Class parametersNameDefaultExplainationwith_timebool: True-with_distancebool: FalseIf True, you will get a distance matrix in addition to the time matrix in the resultskip_waypointsbool: TrueThis will skip waypoints from the response of osrm api, so you will see a performance enhancement by thistime_scale_factorint: 1Scale the resulted times by this scalarapi_urlstr: Comes fromPRIMARY_OSRM_URLconfig. valueThis is the api url of the osrm instanceosm_instances_urlslist: Comes fromOSRM_URLSconfig. valueThis is a list of osrm urlsload_balancebool: FalseIf True, to be not useless we need to setosm_instances_urls, so the package will request from a random instancecache_resultsbool: FalseIf True, you need to passrequest_idto theosm_api.osm_matrixso the key in the redis will be a mix between the info of the function parameters and thisrequest_idmax_api_retriesint: 10If the instance is down, so we will try this number of times before return the resultConfigurationThe configuration of this package is done by an .env file and .yaml file like the following (the following files will have the full configs but onlyPRIMARY_OSRM_URLis mandatory).env file (Optional and the default name ofYAML_CONFIG_FILE_NAMEwill beosm_helper_config.yaml)YAML_CONFIG_FILE_NAME=YOUR_OSM_HELPER_CONFIG.yamlYOUR_OSM_HELPER_CONFIG.yamlNameDefaultExplainationPRIMARY_OSRM_URLhttp://router.project-osrm.orgOSRM url, the default value is the public instance of OSRM.[Optional] OSRM_URLSNoneOSRM Instances[Optional] OSRM_MAX_API_RETRIES10If the instance is down, so we will tryOSRM_MAX_API_RETRIEStimes before return the result[Optional] REDIS_HOSTNoneRedis host url[Optional] REDIS_PORTNoneRedis port[Optional] REDIS_EXPIRATION_TIMEINFINITYRedis records timeout (in seconds)[Optional] REDIS_ASYNC_CACHEFalseIf True, the caching process will be done in async way (To maximize the performance of getting ETA)ContributionYou're welcome!Fork the project and make a pull request I will see it inshallah.