This Python module is a wrapper for Public Transport Victoria (PTV) data API. It allows users to retrieve information about public transport schedules, routes, stops, and other related data made available by PTV.
The purpose of this module is to ease the access of PTV Data API v3 through Python. The endpoints of PTV Data API are presented as methods of PTVClient.
- PTV signature calculation
- API key authentication on initialization
- Supports all PTV API endpoints
-
Download the folder
ptv_api
. -
Install the required packages using
requirements.txt
.pip install -r requirements.txt
You are going to need a pair of Developer ID and API key from Public Transport Victoria
- Create a file named '.env' in the same directory where you import 'ptv_api'.
- The contents should follow the format of '.env_sample'.
- When creating an instance of 'PTVClient', pass the Developer ID and API key as arguments
Import 'PTVClient':
pip install -r requirements.txt
Instantiate a client object:
client = PTVClient() # If you have the .env file set up
# OR
client = PTVClient("API_KEY", DEV_ID)
Access the endpoints through 'PTVClient''s methods:
client.search("South Yarra")
To view departures for the Pakenham line in Southern Cross
departures = client.get_departures_by_stop_and_route(route_type=0, stop_id=1181, route_id=11)
print(departures)
To estimate a fare by zone:
fare_estimate = client.get_fare_estimate(min_zone=1, max_zone=2)
print(fare_estimate)
And so many more...
You can access the list of PTV Endpoints here.
All endpoints have a corresponding method. (Click to expand)
-
get_departures_by_stop
- Endpoint:
/v3/departures/route_type/{route_type}/stop/{stop_id}
- Endpoint:
-
get_departures_by_stop_and_route
- Endpoint:
/v3/departures/route_type/{route_type}/stop/{stop_id}/route/{route_id}
- Endpoint:
-
get_directions_by_route
- Endpoint:
/v3/directions/route/{route_id}
- Endpoint:
-
get_directions_by_direction_id
- Endpoint:
/v3/directions/{direction_id}
- Endpoint:
-
get_direction_by_direction_id_and_route_type
- Endpoint:
/v3/directions/{direction_id}/route_type/{route_type}
- Endpoint:
-
get_disruptions_all
- Endpoint:
/v3/disruptions
- Endpoint:
-
get_disruptions_by_route
- Endpoint:
/v3/disruptions/route/{route_id}
- Endpoint:
-
get_disruptions_by_route_and_stop
- Endpoint:
/v3/disruptions/route/{route_id}/stop/{stop_id}
- Endpoint:
-
get_disruptions_by_stop
- Endpoint:
/v3/disruptions/stop/{stop_id}
- Endpoint:
-
get_disruption_by_id
- Endpoint:
/v3/disruptions/{disruption_id}
- Endpoint:
-
get_disruption_modes
- Endpoint:
/v3/disruptions/modes
- Endpoint:
-
get_fare_estimate
- Endpoint:
/v3/fare_estimate/min_zone/{min_zone}/max_zone/{max_zone}
- Endpoint:
-
get_outlets_all
- Endpoint:
/v3/outlets
- Endpoint:
-
get_outlets_by_geolocation
- Endpoint:
/v3/outlets/location/{latitude},{longitude}
- Endpoint:
-
get_pattern_by_run_ref
- Endpoint:
/v3/pattern/run/{run_ref}/route_type/{route_type}
- Endpoint:
-
get_route_all
- Endpoint:
/v3/routes
- Endpoint:
-
get_route_by_id
- Endpoint:
/v3/routes/{route_id}
- Endpoint:
-
get_route_types
- Endpoint:
/v3/route_types
- Endpoint:
-
get_runs_by_route
- Endpoint:
/v3/runs/route/{route_id}
- Endpoint:
-
get_runs_by_route_and_route_type
- Endpoint:
/v3/runs/route/{route_id}/route_type/{route_type}
- Endpoint:
-
get_run_by_ref
- Endpoint:
/v3/runs/{run_ref}
- Endpoint:
-
get_run_by_ref_and_route_type
- Endpoint:
/v3/runs/{run_ref}/route_type/{route_type}
- Endpoint:
-
search
- Endpoint:
/v3/search/{search_term}
- Endpoint:
-
get_stop_details
- Endpoint:
/v3/stops/{stop_id}/route_type/{route_type}
- Endpoint:
-
get_stops_by_route
- Endpoint:
/v3/stops/route/{route_id}/route_type/{route_type}
- Endpoint:
-
get_stops_by_geolocation
- Endpoint:
/v3/stops/location/{latitude},{longitude}
- Endpoint:
For questions or support, feel free to message me on GitHub.
- Perhaps uploading to PyPi for easier access