landtransportsg.public_transport¶
Public Transport module.
Example usage:
# get the bus arrival information at a bus stop
from landtransportsg import PublicTransport
client = PublicTransport(API_KEY)
bus_arrival = client.bus_arrival('83139')
Methods¶
- class landtransportsg.public_transport.Client(account_key: str, cache_backend: str | BaseCache = 'sqlite')¶
Bases:
LandTransportSgInteract with the public transport-related endpoints.
References: https://datamall.lta.gov.sg/content/dam/datamall/datasets/LTA_DataMall_API_User_Guide.pdf
- bus_arrival(**kwargs: Unpack[BusArrivalArgsDict]) BusArrivalDict¶
Get real-time Bus Arrival information of Bus Services at a queried Bus Stop, including Est. Arrival Time, Est. Current Location, Est. Current Load.
- Parameters:
kwargs (BusArrivalArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError – bus_stop_code is not exactly 5 characters long.
ValueError – bus_stop_code is not a number-like string.
- Returns:
Information about bus arrival at the specified bus stop.
- Return type:
- bus_routes() list[BusRoutesDict]¶
Get detailed route information for all services currently in operation, including: all bus stops along each route, first/last bus timings for each stop.
- Returns:
Information about bus routes currently in operation.
- Return type:
- bus_services() list[BusServicesDict]¶
Get detailed service information for all buses currently in operation, including: first stop, last stop, peak / offpeak frequency of dispatch.
- Returns:
Information about bus services currently in operation.
- Return type:
- bus_stops() list[BusStopsDict]¶
Get detailed information for all bus stops currently being serviced by buses, including: Bus Stop Code, location coordinate.
- Returns:
Location coordinaties of bus stops with active services.
- Return type:
- facilities_maintenance() list[FacilitiesMaintenanceDict]¶
Returns adhoc lift maintenance in MRT stations.
- Returns:
Station codes and namse with IDs of lifts being serviced.
- Return type:
- passenger_volume_by_bus_stops(**kwargs: Unpack[PassengerVolumeArgsDict]) str¶
Get tap in and tap out passenger volume by weekdays and weekends for individual bus stop.
- Parameters:
kwargs (PassengerVolumeArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError – dt is not within the last 3 months.
- Returns:
Download link of file containing passenger volume data.
- Return type:
- passenger_volume_by_origin_destination_bus_stops(**kwargs: Unpack[PassengerVolumeArgsDict]) str¶
Get number of trips by weekdays and weekends from origin to destination bus stops.
- Parameters:
kwargs (PassengerVolumeArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError – dt is not within the last 3 months.
- Returns:
Download link of file containing passenger volume data.
- Return type:
- passenger_volume_by_origin_destination_train_stations(**kwargs: Unpack[PassengerVolumeArgsDict]) str¶
Get number of trips by weekdays and weekends from origin to destination train stations.
- Parameters:
kwargs (PassengerVolumeArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError – dt is not within the last 3 months.
- Returns:
Download link of file containing passenger volume data.
- Return type:
- passenger_volume_by_train_stations(**kwargs: Unpack[PassengerVolumeArgsDict]) str¶
Get tap in and tap out passenger volume by weekdays and weekends for individual train station.
- Parameters:
kwargs (PassengerVolumeArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError – dt is not within the last 3 months.
- Returns:
Download link of file containing passenger volume data.
- Return type:
- planned_bus_routes() list[PlannedBusRoutesDict]¶
Get planned new/updated bus routes information.
Important note: Data to be released only ON/AFTER the Effective Date.
- Returns:
Information about planned bus routes.
- Return type:
- station_crowd_density_forecast(**kwargs: Unpack[StationCrowdDensityArgsDict]) list[StationCrowdDensityForecastDict]¶
Get forecasted MRT/LRT statiion crowdedness level of a particular train network line at 30 minutes interval. Refer to the train_lines() method for the list of valid train network lines.
- Parameters:
kwargs (StationCrowdDensityArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError – train_line is not specified.
ValueError – train_line is not a valid train network line.
- Returns:
Forecasted platform crowdedness level of the specified train network line.
- Return type:
- station_crowd_density_real_time(**kwargs: Unpack[StationCrowdDensityArgsDict]) list[StationCrowdDensityRealTimeDict]¶
Get real-time MRT/LRT station crowdedness level of a particular train network line. Refer to the train_lines() method for the list of valid train network lines.
- Parameters:
kwargs (StationCrowdDensityArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError – train_line is not specified.
ValueError – train_line is not a valid train network line.
- Returns:
Station crowdedness level of the specified train network line.
- Return type:
- taxi_availability() list[TaxiAvailabilityDict]¶
Get location coordinates of all Taxis that are currently available for hire. Does not include “Hired” or “Busy” Taxis.
- Returns:
Location coordinaties of available taxis.
- Return type:
- taxi_stands() list[TaxiStandsDict]¶
Get detailed information of Taxi stands, such as location and whether is it barrier free.
- Returns:
Detailed information of taxi stands.
- Return type:
- train_service_alerts() list[TrainServiceAlertsDict]¶
Get detailed information on train service unavailability during scheduled operating hours, such as affected line and stations etc.
- Returns:
Information about train service unavailability.
- Return type:
Argument Types¶
- class landtransportsg.public_transport.BusArrivalArgsDict¶
Bases:
TypedDictType definition for bus_arrival() input arguments
- service_number: NotRequired[str]¶
Bus service number.
- Example:
“15”
- Default:
None
- class landtransportsg.public_transport.PassengerVolumeArgsDict¶
Bases:
TypedDictType definition for platform_crowd_density_real_time() and platform_crowd_density_forecast() input arguments
- dt: NotRequired[date]¶
Date of a specific month to get passenger volume. Only the year and month are used since those are what the endpoint accepts. Must be within the last 3 months of the current month.
- Example:
date(2019, 7, 2)
- Default:
None
Types¶
- class landtransportsg.public_transport.BusArrivalDict¶
Bases:
TypedDictType definition for bus_arrival()
- class landtransportsg.public_transport._NextBusDict¶
Bases:
TypedDictType definition for _BusArrivalServiceDict
- OriginCode: str¶
Reference code of the first bus stop where this bus started its service.
- Example:
“77009”
- DestinationCode: str¶
Reference code of the last bus stop where this bus will terminate its service.
- Example:
“77131”
- EstimatedArrival: datetime | None¶
Date-time of this bus’ estimated time of arrival.
- Example:
datetime(2017, 4, 29, 7, 20, 24)
- Monitored: int¶
Indicates if the bus arrival time is based on the schedule from operators:
0 - Value from EstimatedArrival is based on schedule.
1 - Value from EstimatedArrival is estimated based on bus location.
- Example:
1
- Latitude: float | None¶
Current estimated location latitude coordinate of this bus at point of published data.
- Example:
1.42117943692586
- Longitude: float | None¶
Current estimated location longitude coordinate of this bus at point of published data.
- Example:
103.831477233098
- VisitNumber: int | None¶
Ordinal value of the nth visit of this vehicle at this bus stop.
1 - 1st visit.
2 - 2nd visit.
etc.
- Example:
1
- class landtransportsg.public_transport.BusRoutesDict¶
Bases:
_BusRoutesDictType definition for bus_routes()
- class landtransportsg.public_transport.BusServicesDict¶
Bases:
TypedDictType definition for bus_services()
- Direction: int¶
The direction in which the bus travels (1 or 2), loop services only have 1 direction.
- Example:
1
- Category: str¶
Category of the SBS bus service:
“EXPRESS”
“FEEDER”
“INDUSTRIAL”
“TOWNLINK”
“TRUNK”
“2 TIER FLAT FEE”
“FLAT FEE $1.10” (or “$1.90”, “$3.50”, “$3.80”)
- Example:
“TRUNK”
- DestinationCode: str¶
Bus stop code for last bus stop (similar as first stop for loop services).
- Example:
“64009”
- AM_Offpeak_Freq: str¶
Freq of dispatch for AM Off-Peak 0831H - 1659H (range in minutes).
- Example:
“10-16”
- class landtransportsg.public_transport.BusStopsDict¶
Bases:
TypedDictType definition for bus_stops()
- class landtransportsg.public_transport.FacilitiesMaintenanceDict¶
Bases:
TypedDictType definition for facilities_maintenance()
- class landtransportsg.public_transport.PlannedBusRoutesDict¶
Bases:
_BusRoutesDictType definition for planned_bus_routes()
- class landtransportsg.public_transport.StationCrowdDensityRealTimeDict¶
Bases:
TypedDictType definition for station_crowd_density_real_time()
- class landtransportsg.public_transport.StationCrowdDensityForecastDict¶
Bases:
TypedDictType definition for station_crowd_density_forecast()
- Stations: list[_StationCrowdDensityForecastStationDict]¶
Array of station crowd density forecast.
- class landtransportsg.public_transport._StationCrowdDensityForecastStationDict¶
Bases:
TypedDictType definition for StationCrowdDensityForecastDict
- Interval: list[_StationCrowdDensityForecastStationIntervalDict]¶
Array of station crowd density forecast per time interval.
- class landtransportsg.public_transport._StationCrowdDensityForecastStationIntervalDict¶
Bases:
TypedDictType definition for StationCrowdDensityForecastStationDict
- class landtransportsg.public_transport.TaxiAvailabilityDict¶
Bases:
TypedDictType definition for taxi_availability()
- class landtransportsg.public_transport.TaxiStandsDict¶
Bases:
TypedDictType definition for taxi_stands()
- Ownership: str¶
Indicate the owner of the Taxi stand.
“LTA” - Land Transport Authority.
“CCS” - Clear Channel Singapore.
“Private” - Taxi facilities that are constructed and maintained by private entities (e.g. developers/owners of shopping malls, commercial buildings).
- Example:
“LTA”