Package: tomtom-api
Tomtom APIAPI client allowing to interact with the tomtom REST services.This module is focused around theTraffic Statsservice.More information about this service can be foundhere.
The API documentation can be foundhere.Installation# Create a virtual environmentpython-mvirtualenvvenv_tomtom_apisourcevenv_tomtom_api/bin/activate# Install static requirements (Optional)pipinstall-rrequirements.txt# Install the package itselfpipinstall.UsageConfigurationThis project is using environment variable as configuration.You are encouraged to store all your environment variable in a.envfile at the root of your folder so it looks like this:TOMTOM_API_KEY=mysuperkeyTOMTOM_API_VERSION=1TOMTOM_API_LOG_LEVEL=debugTOMTOM_API_PROXY_IP=172.0.10.1TOMTOM_API_PROXY_PORT=1234TOMTOM_API_PROXY_USERNAME=userTOMTOM_API_PROXY_PASSWORD=passwordTOMTOM_API_HOME_FOLDER=/var/lib/tomtom_apiTOMTOM_API_QUEUE_LOOP_DURATION=60To check the available names of the environment variables, you can use the commandpython -m tomtom_api list-env.To load all your environment variables, you can use the commandexport $(cat .env).CLIThere are a few actions available through a CLI.
You can list all the commands withpython -m tomtom_api --help.❯ python -m tomtom_api --help
Usage: python -m tomtom_api [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  get-job-info       Display information about a specific job.
  list-all-job-info  Fetch information about the jobs registered.
  list-env           List the configurable environment variables.
  proxy-check        Get your ip with and without the configured proxy.ModuleSome endpoints are not available through the CLI because it is not easy to provide the required structure of the payload.
Then you can import this module in your python script and launch requests through theTomtomClient.Here's how to mimic the payload present in the documentation example:fromtomtom_api.clientimportTomtomClientfromtomtom_api.traffic_stats.models.geospatialimportTomtomPoint,TomtomRoadfromtomtom_api.traffic_stats.models.timeimport(TomtomDateRange,TomtomTimeGroup,TomtomTimeSet)client=TomtomClient()road=TomtomRoad('Some Route',start=TomtomPoint(51.7822,4.61689),end=TomtomPoint(51.78555,4.61076),via=[TomtomPoint(51.78153,4.60559)],full_traversal=False,zone_id='Europe/Amsterdam',probe_source='ALL')date_range=TomtomDateRange('Last working week of January',start='2021-01-25',end='2021-01-29',exclusions=["2021-01-26","2021-01-27"])time_set=TomtomTimeSet(name='Monday morning hour',time_groups=[TomtomTimeGroup(days=['MON'],times=['7:00-8:00'])])response=client.route_analysis('Test job',distance_unit='KILOMETERS',map_version=2020.09,accept_mode='AUTO',roads=[road],date_ranges=[date_range],time_sets=[time_set])And here's another example, just for fun:importcalendarimportdatetimeasdtimportpandasaspdfromtomtom_api.clientimportTomtomClientfromtomtom_api.traffic_stats.models.geospatialimportTomtomPoint,TomtomRoadfromtomtom_api.traffic_stats.models.timeimport(TomtomDateRange,TomtomTimeGroup,TomtomTimeSet)# Geospatial informationstart=TomtomPoint(50.881238,4.434957)via=[TomtomPoint(50.880040,4.435190),TomtomPoint(50.878715,4.431446),TomtomPoint(50.877617,4.420429),TomtomPoint(50.877287,4.415166),TomtomPoint(50.877193,4.413980),]end=TomtomPoint(50.877779,4.413870)roads=[TomtomRoad('Rue de la fusée, Evere, Belgique',probe_source='ALL',start=start,end=end,via=via,full_traversal=False,zone_id='Europe/Brussels')]# Time informationtime_group_all_week=TomtomTimeGroup.from_time_range()time_sets_all_week=[TomtomTimeSet('All week, every 15min',[time_group_all_week])]date_ranges=[TomtomDateRange.from_week(2022,30)]# Clientclient=TomtomClient()response=client.route_analysis('Testing from home',distance_unit='KILOMETERS',roads=roads,date_ranges=date_ranges,time_sets=time_sets_all_week)