octranspo package¶
Submodules¶
octranspo.data module¶
Models for OC Transpo data
-
class
octranspo.data.
BusType
(value)¶ Bases:
enum.Enum
Bus type returned by the API
-
BIKE_RACK
= 5¶
-
DOUBLE_DECKER
= 4¶
-
FORTY_FOOT
= 1¶
-
FORTY_OR_SIXTY
= 3¶
-
HYBRID
= 6¶
-
INVIRO
= 7¶
-
NONE
= 0¶
-
ORION
= 8¶
-
SIXTY_FOOT
= 2¶
-
-
class
octranspo.data.
GTFSAgency
(id: str, agency_name: str, agency_url: str, agency_timezone: str, agency_lang: str)¶ Bases:
object
GTFS entry for the agency table
-
agency_lang
: str¶ The language of the agency
-
agency_name
: str¶ The name of the agency
-
agency_timezone
: str¶ The timezone of the agency
-
agency_url
: str¶ The URL for the agency
-
id
: str¶ Row ID
-
-
class
octranspo.data.
GTFSCalendar
(id: str, service_id: str, monday: bool, tuesday: bool, wednesday: bool, thursday: bool, friday: bool, saturday: bool, sunday: bool, start_date: str, end_date: str)¶ Bases:
object
GTFS entry for the calendar table
-
end_date
: str¶
-
friday
: bool¶
-
id
: str¶ Row ID
-
monday
: bool¶
-
saturday
: bool¶
-
service_id
: str¶
-
start_date
: str¶
-
sunday
: bool¶
-
thursday
: bool¶
-
tuesday
: bool¶
-
wednesday
: bool¶
-
-
class
octranspo.data.
GTFSConfig
(*args, **kwargs)¶ Bases:
dict
Configuration for GTFS API request functions
-
column
: str¶ A specific column in the table
-
direction
: Union[Literal[asc], Literal[desc]]¶ Ascending or descending order for records
-
id
: str¶ Specific row ID to get
-
limit
: int¶ Maximum amount of returned records
-
order_by
: str¶ A column to sort by
-
value
: str¶ A specific value in a column. Required if column is specified
-
-
class
octranspo.data.
NextTripsForStop
(stop_number: str, stop_label: str, routes: List[octranspo.data.RouteWithTrips])¶ Bases:
object
Returned from the GetNextTripsForStop API method
-
routes
: List[octranspo.data.RouteWithTrips]¶ Routes with trip info
-
stop_label
: str¶ Label for the stop (eg. “RIDEAU”)
-
stop_number
: str¶ 4-digit bus stop number
-
-
class
octranspo.data.
NextTripsForStopAllRoutes
(stop_number: str, stop_label: str, routes: List[octranspo.data.RouteWithTripsAllRoutes])¶ Bases:
object
Returned from the GetNextTripsForStopAllRoutes API method
-
routes
: List[octranspo.data.RouteWithTripsAllRoutes]¶ Routes with trip info
-
stop_label
: str¶ Label for the stop (eg. “RIDEAU”)
-
stop_number
: str¶ 4-digit bus stop number
-
-
class
octranspo.data.
Route
(route_number: str, route_heading: str, direction: str, direction_id: int)¶ Bases:
object
Describes an OC Transpo route
-
direction
: str¶ Direction description
-
direction_id
: int¶ Direction identifier
-
route_heading
: str¶ Route heading
-
route_number
: str¶ Route number
-
-
class
octranspo.data.
RouteSummary
(stop_number: str, stop_label: str, routes: List[octranspo.data.Route])¶ Bases:
object
Returned from the GetRouteSummaryForStop API method
-
routes
: List[octranspo.data.Route]¶ The routes for the stop
-
stop_label
: str¶ Label for the stop (eg. “RIDEAU”)
-
stop_number
: str¶ 4-digit bus stop number
-
-
class
octranspo.data.
RouteWithTrips
(route_number: str, route_description: str, direction: str, request_processing_time: str, trips: List[octranspo.data.Trip])¶ Bases:
object
Describes a route with info on future trips
-
direction
: str¶ Direction description
-
request_processing_time
: str¶ The time it took to process the request
-
route_description
: str¶ Route description
-
route_number
: str¶ Route number
-
trips
: List[octranspo.data.Trip]¶ The trips for the route
-
-
class
octranspo.data.
RouteWithTripsAllRoutes
(route_number: str, route_heading: str, direction_id: int, direction: str, trips: List[octranspo.data.Trip])¶ Bases:
object
Describes a route with info on future trips for the GetNextTripsForStopAllRoutes API method
-
direction
: str¶ Direction? Seems to be empty string
-
direction_id
: int¶ Direction ID
-
route_heading
: str¶ Route heading
-
route_number
: str¶ Route number
-
trips
: List[octranspo.data.Trip]¶ The trips for the route
-
-
class
octranspo.data.
Trip
(latitude: str, longitude: str, gps_speed: Literal[], trip_destination: str, trip_start_time: str, adjusted_schedule_time: str, adjustment_age: str, last_trip_of_schedule: bool, bus_type: octranspo.data.BusType)¶ Bases:
object
Describes a trip for a route
-
adjusted_schedule_time
: str¶ Time until trip is estimated to arrive at stop
-
adjustment_age
: str¶ The time since the schedule was adjusted in minutes
-
bus_type
: octranspo.data.BusType¶ The type of bus
-
gps_speed
: Literal[]¶ Removed from API; Blank string
-
last_trip_of_schedule
: bool¶ Whether it is the last trip of the day
-
latitude
: str¶ Latitude
-
longitude
: str¶ Longitude
-
trip_destination
: str¶ Trip heading
-
trip_start_time
: str¶ Scheduled start time for trip
-
octranspo.error module¶
Errors for the wrapper
-
exception
octranspo.error.
APIException
¶ Bases:
octranspo.error.OCBaseException
Base exception for any error returned by the OC Transpo API
-
exception
octranspo.error.
InvalidKeyError
¶ Bases:
octranspo.error.APIException
Invalid API key or App ID
-
exception
octranspo.error.
InvalidRouteError
¶ Bases:
octranspo.error.APIException
Invalid route number
-
exception
octranspo.error.
InvalidStopError
¶ Bases:
octranspo.error.APIException
Invalid stop number
-
exception
octranspo.error.
MissingKeyError
¶ Bases:
octranspo.error.OCBaseException
App ID and/or API Key was not provided
-
exception
octranspo.error.
NoRoutesOnStopError
¶ Bases:
octranspo.error.APIException
No routes available at stop at any time
-
exception
octranspo.error.
OCBaseException
¶ Bases:
Exception
Base exception for all OC Transpo errors
-
exception
octranspo.error.
QueryError
¶ Bases:
octranspo.error.APIException
Unable to query data source
-
exception
octranspo.error.
StopDoesntServiceError
¶ Bases:
octranspo.error.APIException
Stop does not service route at this time
octranspo.octranspo module¶
Contains the main OC Transpo class
-
class
octranspo.octranspo.
OCTranspo
(app_id: Optional[str] = None, api_key: Optional[str] = None)¶ Bases:
object
The main OC Transpo class
- Parameters
app_id (str) – OC Transpo-provided App ID
api_key (str) – OC Transpo-provided API Key
-
get_gtfs_table
(table: Union[Literal[agency], Literal[calendar], Literal[calendar_dates], Literal[routes], Literal[stops], Literal[stop_times], Literal[trips]], **kwargs: octranspo.data.GTFSConfig) → dict¶ Get the results from a specified GTFS table
- Parameters
table (GTFSTable) – The table ID
- Raises
APIException – Any error received from the API
- Returns
The parsed returned data
- Return type
dict
-
get_next_trips
(stop: str, route_number: str) → octranspo.data.NextTripsForStop¶ Gets the trips for a given stop and route number. Route numbers can be retrieved with OCTranspo.get_route_summary
- Parameters
stop (str) – The 4-digit stop number
route_number (str) – The route number
- Raises
APIException – Any error received from the API
- Returns
The returned data
- Return type
-
get_next_trips_all_routes
(stop: str) → octranspo.data.NextTripsForStopAllRoutes¶ Gets the trips for all routes for a given stop number.
- Parameters
stop (str) – The 4-digit stop number
- Raises
APIException – Any error received from the API
- Returns
The returned data
- Return type
-
get_route_summary
(stop: str) → octranspo.data.RouteSummary¶ Get the routes for a given stop number
- Parameters
stop (str) – The 4-digit stop number
- Raises
APIException – Any error received from the API
- Returns
The route info
- Return type
-
gtfs_agency
(**kwargs: octranspo.data.GTFSConfig) → List[octranspo.data.GTFSAgency]¶ Get the agency table from the GTFS API
- Raises
APIException – Any error received from the API
- Returns
Data from the agency table
- Return type
List[GTFSAgency]
-
gtfs_calendar
(**kwargs: octranspo.data.GTFSConfig) → List[octranspo.data.GTFSCalendar]¶ Get the calendar table from the GTFS API
- Raises
APIException – Any error received from the API
- Returns
Data from the calendar table
- Return type
List[GTFSCalendar]
-
octranspo.octranspo.
api_errors
(response: dict, main_key: str) → dict¶ Throw errors returned by the API
- Parameters
response (dict) – The API response
main_key (str) – The main key in the response (eg. GetRouteSummaryForStopResult)
- Raises
APIException – Any error received from the API
- Returns
If no error is thrown, response[main_key]
- Return type
dict
-
octranspo.octranspo.
bus_to_enum
(bus_type: str) → octranspo.data.BusType¶ Convert an API-returned bus type to an enum
- Parameters
bus_type (str) – The bus type returned by the API
- Returns
An enum representation of the bus type
- Return type
Module contents¶
A Python wrapper around the OC Transpo API