Python Interface to Travel Time
Project description
traveltimePY: Travel Time Python SDK
traveltimePY is a Python SDK for Travel Time API (https://traveltime.com/).
Travel Time API helps users find locations by journey time rather than using ‘as the crow flies’ distance.
Time-based searching gives users more opportunities for personalisation and delivers a more relevant search.
Dependencies:
- requests
Installation
pip install traveltimepy
Usage
Authentication
In order to authenticate with Travel Time API, you will have to supply the Application Id and Api Key.
import traveltimepy as ttpy
import os
from datetime import datetime #for examples
#store your credentials in an environment variable
os.environ["TRAVELTIME_ID"] = 'YOUR_API_ID'
os.environ["TRAVELTIME_KEY"] = 'YOUR_API_KEY'
Isochrones (Time Map)
Given origin coordinates, find shapes of zones reachable within corresponding travel time.
departure_search1 = {
'id': "public transport from Trafalgar Square",
'departure_time': datetime.utcnow().isoformat(),
'travel_time': 900,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'properties': ['is_only_walking']
}
departure_search2 = {
'id': "driving from Trafalgar Square",
'departure_time': datetime.utcnow().isoformat(),
'travel_time': 900,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "driving"}
}
arrival_search = {
'id': "public transport to Trafalgar Square",
'arrival_time': datetime.utcnow().isoformat(),
'travel_time': 900,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'range': {'enabled': True, 'width': 3600}
}
union = {
'id': "union of driving and public transport",
'search_ids': ['driving from Trafalgar Square', 'public transport from Trafalgar Square']
}
intersection = {
'id': "intersection of driving and public transport",
'search_ids': ['driving from Trafalgar Square', 'public transport from Trafalgar Square']
}
out = ttpy.time_map(departure_searches=[departure_search1, departure_search2],
arrival_searches=arrival_search, unions=union, intersections=intersection)
Distance Matrix (Time Filter)
Given origin and destination points filter out points that cannot be reached within specified time limit.
locations = [
{"id": "London center", "coords": {"lat": 51.508930, "lng": -0.131387}},
{"id": "Hyde Park", "coords": {"lat": 51.508824, "lng": -0.167093}},
{"id": "ZSL London Zoo", "coords": {"lat": 51.536067, "lng": -0.153596}}
]
departure_search = {
"id": "forward search example",
"departure_location_id": "London center",
"arrival_location_ids": ["Hyde Park", "ZSL London Zoo"],
"transportation": {"type": "bus"},
"departure_time": datetime.utcnow().isoformat(),
"travel_time": 1800,
"properties": ["travel_time"],
"range": {"enabled": True, "max_results": 3, "width": 600}
}
arrival_search = {
"id": "backward search example",
"departure_location_ids": ["Hyde Park", "ZSL London Zoo"],
"arrival_location_id": "London center",
"transportation": {"type": "public_transport"},
"arrival_time": datetime.utcnow().isoformat(),
"travel_time": 1900,
"properties": ["travel_time", "distance", "distance_breakdown", "fares"]
}
out = ttpy.time_filter(
locations=locations, departure_searches=departure_search, arrival_searches=arrival_search)
Routes
Returns routing information between source and destinations.
locations = [
{"id": "London center", "coords": {"lat": 51.508930, "lng": -0.131387}},
{"id": "Hyde Park", "coords": {"lat": 51.508824, "lng": -0.167093}},
{"id": "ZSL London Zoo", "coords": {"lat": 51.536067, "lng": -0.153596}}
]
departure_search = {
"id": "departure search example",
"departure_location_id": "London center",
"arrival_location_ids": ["Hyde Park", "ZSL London Zoo"],
"transportation": {"type": "driving"},
"departure_time": datetime.utcnow().isoformat(),
"properties": ["travel_time", "distance", "route"]
}
arrival_search = {
"id": "arrival search example",
"departure_location_ids": ["Hyde Park", "ZSL London Zoo"],
"arrival_location_id": "London center",
"transportation": {"type": "public_transport"},
"arrival_time": datetime.utcnow().isoformat(),
"properties": ["travel_time", "distance", "route", "fares"],
"range": {"enabled": True, "max_results": 1, "width": 1800}
}
out = ttpy.routes(
locations=locations, departure_searches=departure_search, arrival_searches=arrival_search)
Time Filter (Fast)
A very fast version of time_filter()
locations = [
{"id": "London center", "coords": {"lat": 51.508930, "lng": -0.131387}},
{"id": "Hyde Park", "coords": {"lat": 51.508824, "lng": -0.167093}},
{"id": "ZSL London Zoo", "coords": {"lat": 51.536067, "lng": -0.153596}}
]
arrival_many_to_one = {
"id": "arrive-at many-to-one search example",
"departure_location_ids": ["Hyde Park","ZSL London Zoo"],
"arrival_location_id": "London center",
"transportation": {"type": "public_transport"},
"arrival_time_period": "weekday_morning",
"travel_time": 1900,
"properties": ["travel_time","fares"]
}
arrival_one_to_many = {
"id": "arrive-at one-to-many search example",
"arrival_location_ids": ["Hyde Park","ZSL London Zoo"],
"departure_location_id": "London center",
"transportation": {"type": "public_transport"},
"arrival_time_period": "weekday_morning",
"travel_time": 1900,
"properties": ["travel_time","fares"]
}
out = ttpy.time_filter_fast(
locations=locations, arrival_many_to_one=arrival_many_to_one, arrival_one_to_many=arrival_one_to_many)
Time Filter (Postcode Districts)
Find reachable postcodes from origin (or to destination) and get statistics about such postcodes.
departure_search = {
'id': "public transport from Trafalgar Square",
'departure_time': datetime.utcnow().isoformat(),
'travel_time': 1800,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'properties': ["coverage", "travel_time_reachable", "travel_time_all"],
"reachable_postcodes_threshold": 0.1
}
arrival_search = {
'id': "public transport to Trafalgar Square",
'arrival_time': datetime.utcnow().isoformat(),
'travel_time': 1800,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'properties': ["coverage", "travel_time_reachable", "travel_time_all"],
"reachable_postcodes_threshold": 0.1
}
out = ttpy.time_filter_postcode_districts(departure_searches=departure_search, arrival_searches=arrival_search)
Time Filter (Postcode Sectors)
Find sectors that have a certain coverage from origin (or to destination) and get statistics about postcodes within such sectors.
departure_search = {
'id': "public transport from Trafalgar Square",
'departure_time': datetime.utcnow().isoformat(),
'travel_time': 1800,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'properties': ["coverage", "travel_time_reachable", "travel_time_all"],
"reachable_postcodes_threshold": 0.1
}
arrival_search = {
'id': "public transport to Trafalgar Square",
'arrival_time': datetime.utcnow().isoformat(),
'travel_time': 1800,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'properties': ["coverage", "travel_time_reachable", "travel_time_all"],
"reachable_postcodes_threshold": 0.1
}
out = ttpy.time_filter_postcode_sectors(departure_searches=departure_search, arrival_searches=arrival_search)
Time Filter (Postcodes)
Find reachable postcodes from origin (or to destination) and get statistics about such postcodes.
departure_search = {
'id': "public transport from Trafalgar Square",
'departure_time': datetime.utcnow().isoformat(),
'travel_time': 1800,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'properties': ["travel_time", "distance"]
}
arrival_search = {
'id': "public transport to Trafalgar Square",
'arrival_time': datetime.utcnow().isoformat(),
'travel_time': 1800,
'coords': {'lat': 51.507609, 'lng': -0.128315},
'transportation': {'type': "public_transport"},
'properties': ["travel_time", "distance"]
}
out = ttpy.time_filter_postcodes(departure_searches=departure_search, arrival_searches=arrival_search)
Geocoding (Search) and Reverse Geocoding
Match a query string to geographic coordinates or match a latitude, longitude pair to an address.
out1 = ttpy.geocoding('Parliament square')
out2 = ttpy.geocoding_reverse(lat=51.507281, lng=-0.132120)
Map Info and Supported Locations
Get information about currently supported countries and find out what points are supported by the api.
out1 = ttpy.map_info()
locations = [
{"id": "Kaunas", "coords": {"lat": 54.900008, "lng": 23.957734}},
{"id": "London", "coords": {"lat": 51.506756, "lng": -0.128050}},
{"id": "Bangkok", "coords": {"lat": 13.761866, "lng": 100.544818}},
{"id": "Lisbon", "coords": {"lat": 38.721869, "lng": -9.138549}}
]
out2 = ttpy.supported_locations(locations=locations)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for traveltimepy-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c7d5a0018c82be6543f5c0e34e0c06fc4525ea64294c50da562e1a2ec3cf8a7 |
|
MD5 | 5c413eaacd0f9ccd533588281df3dbce |
|
BLAKE2b-256 | 04401b2c43775e139722386fca4fe3a14e7da968c772ab177ba4c35a372df7f6 |