Travel Time API Python Client
Traveltimepy is the official Python client for the Travel Time API, providing functionality to calculate travel times and distances between locations, search reachable areas, and find routes. It supports various transportation modes (driving, cycling, public transport, walking). The current stable version is 4.6.1, with regular updates to keep pace with API features and Python ecosystem changes.
Common errors
-
traveltimepy.errors.TravelTimeError: Authentication failed (403 Forbidden)
cause Invalid `application_id` or `api_key` provided to the client, or the credentials do not have access to the requested API endpoint.fixVerify that your `TRAVELTIME_APP_ID` and `TRAVELTIME_API_KEY` environment variables (or direct parameters) match the credentials from your Travel Time Platform account. Check for typos or leading/trailing spaces. -
AttributeError: module 'traveltimepy' has no attribute 'TravelTimeSDK'
cause Attempting to use the old `TravelTimeSDK` class from version 3.x with a version 4.x installation.fixUpdate your code to use `TravelTimeClient` instead of `TravelTimeSDK`. The import should be `from traveltimepy import TravelTimeClient`. -
pydantic.error_wrappers.ValidationError: 1 validation error for Coords\nlat\n value is not a valid float
cause A `lat` (latitude) value provided to a `Coords` object was not a valid float (e.g., it was a string that couldn't be parsed).fixEnsure that both `lat` and `lng` values passed to `Coords` are valid `float` numbers. Convert strings to floats if necessary (e.g., `Coords(lat=float('51.5'), lng=float('-0.1'))`).
Warnings
- breaking Version 4.0.0 of `traveltimepy` introduced a complete rewrite of the SDK. The client initialization, data structures (e.g., Location, Transportation), and method signatures changed significantly.
- gotcha The API requires both an `application_id` and an `api_key`. Ensure these are correctly provided during client initialization, ideally via environment variables to avoid hardcoding credentials.
- gotcha When using `Coords` objects, ensure `lat` and `lng` are provided as floats. Incorrect data types can lead to `pydantic.ValidationError` or API errors.
Install
-
pip install traveltimepy
Imports
- TravelTimeClient
from traveltimepy import TravelTimeSDK
from traveltimepy import TravelTimeClient
- Location
from traveltimepy import Location
- Coords
from traveltimepy import Coords
Quickstart
import os
from traveltimepy import TravelTimeClient
# Initialize the Travel Time API client.
# Ensure TRAVELTIME_APP_ID and TRAVELTIME_API_KEY environment variables are set
# with your credentials obtained from the Travel Time Platform.
client = TravelTimeClient(
application_id=os.environ.get('TRAVELTIME_APP_ID', 'your_app_id_here'),
api_key=os.environ.get('TRAVELTIME_API_KEY', 'your_api_key_here')
)
# The 'client' object is now ready to make API calls,
# e.g., client.time_filter(...), client.time_map(...).
# For detailed examples, refer to the official documentation or GitHub README.