siri_transit_api_client package¶
Submodules¶
siri_transit_api_client.exceptions module¶
Defines exceptions that are thrown by the api client.
- exception siri_transit_api_client.exceptions.ApiError(status, message=None)¶
Bases:
ExceptionRepresents an exception returned by the remote API.
- exception siri_transit_api_client.exceptions.HTTPError(status_code)¶
Bases:
TransportErrorAn unexpected HTTP error occurred.
- exception siri_transit_api_client.exceptions.OverQueryLimit(status, message=None)¶
Bases:
ApiError,RetriableRequestSignifies that the request failed because the client exceeded its query rate limit. Normally we treat this as a retriable condition, but we allow the calling code to specify that these requests should not be retried.
- exception siri_transit_api_client.exceptions.RetriableRequest¶
Bases:
ExceptionSignifies that the request can be retried.
- exception siri_transit_api_client.exceptions.Timeout¶
Bases:
ExceptionThe request timed out.
- exception siri_transit_api_client.exceptions.TransportError(base_exception=None)¶
Bases:
ExceptionSomething went wrong while trying to execute the request.
siri_transit_api_client.holidays module¶
siri_transit_api_client.lines module¶
siri_transit_api_client.operators module¶
siri_transit_api_client.patterns module¶
siri_transit_api_client.siri_client module¶
Description: This file contains a class to query Siri data from 511.org. This class takes inspiration from https://github.com/googlemaps/google-maps-services-python
@author: Robert Hennessy (robertghennessy@gmail.com)
- class siri_transit_api_client.siri_client.SiriClient(api_key: str = None, base_url: str = 'https://api.511.org/Transit/', retry_timeout: int = 60, queries_per_second: int = 10, retry_over_query_limit: bool = True, requests_session: Session = None, requests_kwargs: dict = None)¶
Bases:
objectCreate session to query the SIRI transit data from 511.org
- Parameters:
api_key (str) – string that contains the api key for 511.org
base_url (str) – weblink to 511 api
retry_timeout (int) – Timeout across multiple retriable requests, in seconds.
queries_per_second (int) – Number of queries per second permitted. If the rate limit is reached, the client will sleep for the appropriate amount of time before it runs the current query.
retry_over_query_limit (bool) – If True, requests that result in a response indicating the query rate limit was exceeded will be retried. Defaults to True.
requests_session (requests.Session) – Reused persistent session for flexibility.
requests_kwargs (dict) – Extra keyword arguments for the requests’ library
- holidays(operator_id: str, accept_language: str = None) dict¶
Query the 511 api to get the holidays for a transit operator.
- Parameters:
operator_id (str) – filter a particular operator id/code
accept_language (str, optional) – select desired language. if unsupported, will return default language.
- Returns:
Results of the query
- Return type:
dict
- lines(operator_id: str, accept_language: str = None, line_id: str = None) dict¶
Query the 511 api to get the routes covered by transit operators within the jurisdiction. Can list all routes or filter using line_id.
- Parameters:
operator_id (str) – filter a particular operator id/code
accept_language (str, optional) – select desired language. if unsupported, will return default language.
line_id (str, optional) – filter based on a particular line
- Returns:
Results of the query
- Return type:
dict
- operators(accept_language: str = None, operator_id: str = None) dict¶
Query api to collect list of all the public transit operators within the jurisdiction.
- Parameters:
accept_language (str, optional) – select desired language. if unsupported, will return default language.
operator_id (str, optional) – filter based on a particular operator id/code
- Returns:
Results of the query
- Return type:
dict
- patterns(operator_id: str, line_id: str, accept_language: str = None, pattern_id: str = None) dict¶
Query api to get the pattern, an ordered list of stop points and time points for a Line.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
line_id (str) – filter based on particular line
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
pattern_id (str, optional) – filter based on a particular pattern. The pattern_id should correspond to the id attribute of a ServiceJourneyPattern returned by the Pattern API.
- Returns:
Results of the query
- Return type:
dict
- shapes(operator_id: str, trip_id: str, accept_language: str = None) dict¶
Query api to get the path that a vehicle travels along a trip.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
trip_id (str) – filter based on particular trip
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
- Returns:
Results of the query
- Return type:
dict
- stop_monitoring(agency: str, stop_code: str = None) dict¶
Collect stop monitoring information which provides current and forthcoming vehicles arrivals and departures at a stop.
- Parameters:
agency (str) – agency ID to be monitored
stop_code (str, optional) – stop ID to be monitored
- Returns:
Results of the query
- Return type:
dict
- stop_places(operator_id: str, accept_language: str = None, stop_id: str = None)¶
Query to get a named place or the physical stop where public transport may be accessed. C
- Parameters:
operator_id (str) – filter for operator
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
stop_id (str, optional) – filter for a stop
- Returns:
Results of the query
- Return type:
dict
- stop_timetable(operator_id: str, stop_code: str, line_id: str = None, start_time: str = None, end_time: str = None) dict¶
Query the api stop static/scheduled timetables in the system for a particular stop
- Parameters:
operator_id (str) – filters based on a particular operator id/code
stop_code (str) – The StopCode that uniquely identifies a physical stop or platform.
line_id (str, optional) – filter based on particular line
start_time (str, optional) – The start date parameter allows for requesting departures within a departure window.
end_time (str, optional) – The end date parameter allows for requesting departures within a departure window.
- Returns:
Results of the query
- Return type:
dict
- stops(operator_id: str, accept_language: str = None, line_id: str = None, include_stop_areas: bool = False, direction_id: str = None, pattern_id: str = None) dict¶
Query api to get location where passengers can board or leave from vehicles.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
line_id (str, optional) – filter based on particular line
include_stop_areas (bool, optional) – When true, all stop areas (stop groupings) along with the referenced stops (ScheduledStopPoints) are returned.
direction_id (str, optional) – filter based on a particular route and direction. line_id also needs to be provided. The direction_id should correspond to value returned by the Pattern API for the operator and route.
pattern_id (str, optional) – filter based on a particular pattern. The pattern_id should correspond to the id attribute of a ServiceJourneyPattern returned by the Pattern API.
- Returns:
Results of the query
- Return type:
dict
- timetable(operator_id: str, line_id: str, accept_language: str = None, include_day_type_assignments: bool = None, include_special_service: bool = False, exception_date: date = None) dict¶
Query api to get the timetable for a given Line, Direction and DayType.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
line_id (str) – filter based on particular line
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
include_day_type_assignments (bool, optional) – DayTypeAssignments will be included only if this flag is set to true.
include_special_service (bool, optional) – If set to true, exceptions for the selected line are returned
exception_date (datetime.date, optional) – provide timetable during holiday/exception date. If nothing returned, service not provide on that date
- Returns:
Results of the query
- Return type:
dict
- vehicle_monitoring(agency: str, vehicle_id: str = None) dict¶
Collect stop monitoring information which provides current and forthcoming vehicles arrivals and departures at a stop.
- Parameters:
agency (str) – agency ID to be monitored
vehicle_id (str, optional) – vehicle ID to be monitored
- Returns:
Results of the query
- Return type:
dict
siri_transit_api_client.stop_monitoring module¶
siri_transit_api_client.stop_places module¶
siri_transit_api_client.stop_timetable module¶
siri_transit_api_client.stops module¶
siri_transit_api_client.timetable module¶
siri_transit_api_client.vehicle_monitoring module¶
Module contents¶
Top-level package for SIRI Transit API Client.
- class siri_transit_api_client.SiriClient(api_key: str = None, base_url: str = 'https://api.511.org/Transit/', retry_timeout: int = 60, queries_per_second: int = 10, retry_over_query_limit: bool = True, requests_session: Session = None, requests_kwargs: dict = None)¶
Bases:
objectCreate session to query the SIRI transit data from 511.org
- Parameters:
api_key (str) – string that contains the api key for 511.org
base_url (str) – weblink to 511 api
retry_timeout (int) – Timeout across multiple retriable requests, in seconds.
queries_per_second (int) – Number of queries per second permitted. If the rate limit is reached, the client will sleep for the appropriate amount of time before it runs the current query.
retry_over_query_limit (bool) – If True, requests that result in a response indicating the query rate limit was exceeded will be retried. Defaults to True.
requests_session (requests.Session) – Reused persistent session for flexibility.
requests_kwargs (dict) – Extra keyword arguments for the requests’ library
- holidays(operator_id: str, accept_language: str = None) dict¶
Query the 511 api to get the holidays for a transit operator.
- Parameters:
operator_id (str) – filter a particular operator id/code
accept_language (str, optional) – select desired language. if unsupported, will return default language.
- Returns:
Results of the query
- Return type:
dict
- lines(operator_id: str, accept_language: str = None, line_id: str = None) dict¶
Query the 511 api to get the routes covered by transit operators within the jurisdiction. Can list all routes or filter using line_id.
- Parameters:
operator_id (str) – filter a particular operator id/code
accept_language (str, optional) – select desired language. if unsupported, will return default language.
line_id (str, optional) – filter based on a particular line
- Returns:
Results of the query
- Return type:
dict
- operators(accept_language: str = None, operator_id: str = None) dict¶
Query api to collect list of all the public transit operators within the jurisdiction.
- Parameters:
accept_language (str, optional) – select desired language. if unsupported, will return default language.
operator_id (str, optional) – filter based on a particular operator id/code
- Returns:
Results of the query
- Return type:
dict
- patterns(operator_id: str, line_id: str, accept_language: str = None, pattern_id: str = None) dict¶
Query api to get the pattern, an ordered list of stop points and time points for a Line.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
line_id (str) – filter based on particular line
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
pattern_id (str, optional) – filter based on a particular pattern. The pattern_id should correspond to the id attribute of a ServiceJourneyPattern returned by the Pattern API.
- Returns:
Results of the query
- Return type:
dict
- shapes(operator_id: str, trip_id: str, accept_language: str = None) dict¶
Query api to get the path that a vehicle travels along a trip.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
trip_id (str) – filter based on particular trip
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
- Returns:
Results of the query
- Return type:
dict
- stop_monitoring(agency: str, stop_code: str = None) dict¶
Collect stop monitoring information which provides current and forthcoming vehicles arrivals and departures at a stop.
- Parameters:
agency (str) – agency ID to be monitored
stop_code (str, optional) – stop ID to be monitored
- Returns:
Results of the query
- Return type:
dict
- stop_places(operator_id: str, accept_language: str = None, stop_id: str = None)¶
Query to get a named place or the physical stop where public transport may be accessed. C
- Parameters:
operator_id (str) – filter for operator
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
stop_id (str, optional) – filter for a stop
- Returns:
Results of the query
- Return type:
dict
- stop_timetable(operator_id: str, stop_code: str, line_id: str = None, start_time: str = None, end_time: str = None) dict¶
Query the api stop static/scheduled timetables in the system for a particular stop
- Parameters:
operator_id (str) – filters based on a particular operator id/code
stop_code (str) – The StopCode that uniquely identifies a physical stop or platform.
line_id (str, optional) – filter based on particular line
start_time (str, optional) – The start date parameter allows for requesting departures within a departure window.
end_time (str, optional) – The end date parameter allows for requesting departures within a departure window.
- Returns:
Results of the query
- Return type:
dict
- stops(operator_id: str, accept_language: str = None, line_id: str = None, include_stop_areas: bool = False, direction_id: str = None, pattern_id: str = None) dict¶
Query api to get location where passengers can board or leave from vehicles.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
line_id (str, optional) – filter based on particular line
include_stop_areas (bool, optional) – When true, all stop areas (stop groupings) along with the referenced stops (ScheduledStopPoints) are returned.
direction_id (str, optional) – filter based on a particular route and direction. line_id also needs to be provided. The direction_id should correspond to value returned by the Pattern API for the operator and route.
pattern_id (str, optional) – filter based on a particular pattern. The pattern_id should correspond to the id attribute of a ServiceJourneyPattern returned by the Pattern API.
- Returns:
Results of the query
- Return type:
dict
- timetable(operator_id: str, line_id: str, accept_language: str = None, include_day_type_assignments: bool = None, include_special_service: bool = False, exception_date: date = None) dict¶
Query api to get the timetable for a given Line, Direction and DayType.
- Parameters:
operator_id (str) – filters based on a particular operator id/code
line_id (str) – filter based on particular line
accept_language (str, optional) – select desired language. if language unsupported, will return default language.
include_day_type_assignments (bool, optional) – DayTypeAssignments will be included only if this flag is set to true.
include_special_service (bool, optional) – If set to true, exceptions for the selected line are returned
exception_date (datetime.date, optional) – provide timetable during holiday/exception date. If nothing returned, service not provide on that date
- Returns:
Results of the query
- Return type:
dict
- vehicle_monitoring(agency: str, vehicle_id: str = None) dict¶
Collect stop monitoring information which provides current and forthcoming vehicles arrivals and departures at a stop.
- Parameters:
agency (str) – agency ID to be monitored
vehicle_id (str, optional) – vehicle ID to be monitored
- Returns:
Results of the query
- Return type:
dict