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)¶
Bases:
LtaInteract with the public transport-related endpoints.
References: https://datamall.lta.gov.sg/content/dam/datamall/datasets/LTA_DataMall_API_User_Guide.pdf
- Parameters:
account_key (str)
- bus_arrival(bus_stop_code: str, service_number: str | None = None) BusArrivalDict | dict¶
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:
- 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 | dict]¶
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 | dict]¶
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 | dict]¶
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(station_code: str) str¶
Get the pre-signed links to JSON file containing facilities maintenance schedules of the particular station.
- Parameters:
station_code (str) – Station Code of train station. Example: “NS1”.
- Raises:
ValueError – station_code is not specified.
ValueError – station_code does not match the expected regex pattern.
- Returns:
Link for downloading the requested JSON file.
- Return type:
Url
- passenger_volume_by_bus_stops(dt: date | None = None) str¶
Get tap in and tap out passenger volume by weekdays and weekends for individual bus stop.
- Parameters:
dt (date) – Date of a specific month to get passenger volume. This must be a valid date object, e.g. date(2019, 7, 2). But only the year and month will be used since that is what the endpoint accepts. Must be within the last 3 months of the current month. Defaults to None.
- Returns:
Download link of file containing passenger volume data.
- Return type:
Url
- passenger_volume_by_origin_destination_bus_stops(dt: date | None = None) str¶
Get number of trips by weekdays and weekends from origin to destination bus stops.
- Parameters:
dt (date) – Date of a specific month to get passenger volume. This must be a valid date object, e.g. date(2019, 7, 2). But only the year and month will be used since that is what the endpoint accepts. Must be within the last 3 months of the current month. Defaults to None.
- Returns:
Download link of file containing passenger volume data.
- Return type:
Url
- passenger_volume_by_origin_destination_train_stations(dt: date | None = None) str¶
Get number of trips by weekdays and weekends from origin to destination train stations.
- Parameters:
dt (date) – Date of a specific month to get passenger volume. This must be a valid date object, e.g. date(2019, 7, 2). But only the year and month will be used since that is what the endpoint accepts. Must be within the last 3 months of the current month. Defaults to None.
- Returns:
Download link of file containing passenger volume data.
- Return type:
Url
- passenger_volume_by_train_stations(dt: date | None = None) str¶
Get tap in and tap out passenger volume by weekdays and weekends for individual train station.
- Parameters:
dt (date) – Date of a specific month to get passenger volume. This must be a valid date object, e.g. date(2019, 7, 2). But only the year and month will be used since that is what the endpoint accepts. Must be within the last 3 months of the current month. Defaults to None.
- Returns:
Download link of file containing passenger volume data.
- Return type:
Url
- platform_crowd_density_forecast(train_line: str) list[PlatformCrowdDensityForecastDict | dict]¶
Get forecasted platform crowdedness level for the MRT/LRT stations 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:
train_line (str) – Code of train network line.
- 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:
- platform_crowd_density_real_time(train_line: str) list[PlatformCrowdDensityRealTimeDict | dict]¶
Get real-time platform crowdedness level for the MRT/LRT stations of a particular train network line. Refer to the train_lines() method for the list of valid train network lines.
- Parameters:
train_line (str) – Code of train network line.
- Raises:
ValueError – train_line is not specified.
ValueError – train_line is not a valid train network line.
- Returns:
Platform crowdedness level of the specified train network line.
- Return type:
- taxi_availability() list[TaxiAvailabilityDict | dict]¶
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 | dict]¶
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:
Types¶
- class landtransportsg.public_transport.BusArrivalDict¶
Bases:
TypedDictType definition for bus_arrival()
- Operator: str¶
Public Transport Operator Codes: - “SBST” - for SBS Transit. - “SMRT” - for SMRT Corporation. - “TTS” - for Tower Transit Singapore. - “GAS” - for Go Ahead Singapore. Example: “GAS”.
- NextBus: _NextBusDict¶
Bus-level attributes of the 1st next oncoming bus.
- NextBus2: _NextBusDict¶
Bus-level attributes of the 2nd next oncoming bus.
- NextBus3: _NextBusDict¶
Bus-level attributes of the 3rd next oncoming bus.
- class landtransportsg.public_transport._NextBusDict¶
Bases:
TypedDictType definition for BusArrivalDict
- 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¶
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: str¶
Current estimated location latitude coordinate of this bus at point of published data. Example: “1.42117943692586”.
- Longitude: str¶
Current estimated location longitude coordinate of this bus at point of published data. Example: “103.831477233098”.
- VisitNumber: str¶
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.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¶
EXPRESS, FEEDER, INDUSTRIAL, TOWNLINK, TRUNK, 2 TIER FLAT FEE, FLAT FEE $1.10 (or $1.90, $3.50, $3.80). Example: “TRUNK”.
- Type:
Category of the SBS bus service
- 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.BusRoutesDict¶
Bases:
TypedDictType definition for bus_routes()
- Direction: int¶
The direction in which the bus travels (1 or 2), loop services only have 1 direction. Example: 1.
- class landtransportsg.public_transport.BusStopsDict¶
Bases:
TypedDictType definition for bus_stops()
- class landtransportsg.public_transport.PlatformCrowdDensityRealTimeDict¶
Bases:
TypedDictType definition for platform_crowd_density_real_time()
- class landtransportsg.public_transport.PlatformCrowdDensityForecastDict¶
Bases:
TypedDictType definition for platform_crowd_density_forecast()
- Stations: list[_PlatformCrowdDensityForecastStationDict]¶
Array of platform crowd density forecast per station.
- class landtransportsg.public_transport._PlatformCrowdDensityForecastStationDict¶
Bases:
TypedDictType definition for PlatformCrowdDensityForecastDict
- Interval: list[_PlatformCrowdDensityForecastStationIntervalDict]¶
Array of platform crowd density forecast per station per time interval.
- class landtransportsg.public_transport._PlatformCrowdDensityForecastStationIntervalDict¶
Bases:
TypedDictType definition for PlatformCrowdDensityForecastStationDict
- 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”.
- class landtransportsg.public_transport.TrainServiceAlertsDict¶
Bases:
TypedDictType definition for train_service_alerts()
- Status: int¶
Indicates if train service is unavailable: - 1 - for Normal Train Service. - 2 - for Disrupted Train Service. Example: 1.
- Line: str¶
Train network line affected: - “CCL” - for Circle Line. - “CEL” - for Circle Line Extension - BayFront, Marina Bay. - “CGL” - for Changi Extension - Expo, Changi Airport. - “DTL” - for Downtown Line. - “EWL” - for East West Line. - “NEL” - for North East Line. - “NSL” - for North South Line. - “PEL” - for Punggol LRT East Loop. - “PWL” - for Punggol LRT West Loop. - “SEL” - for Sengkang LRT East Loop. - “SWL” - For Sengkang LRT West Loop. - “BPL” - for Bukit Panjang LRT. Example: “NEL”.
- Direction: str¶
Indicates direction of service unavailability on the affected line: - “Both”. - towards station name. Example: “Punggol”.
- Stations: str¶
Indicates the list of affected stations on the affected line. Example: “NE1,NE3,NE4,NE5,NE6”.
- FreePublicBus: str¶
Indicates the list of affected stations where free boarding onto normal public bus services are available. - station code. - “Free bus service island wide”. Example: “NE1,NE3,NE4,NE5,NE6”.
- FreeMRTShuttle: str¶
Indicates the list of affected stations where free MRT shuttle services^ are available. - station code. - “EW21|CC22,EW23,EW24|NS1,EW27;NS9,NS13,NS16,NS17|CC15;EW8|CC9,EW5,EW2;NS1|EW24,NS4|BP1*”. Example: “NE1,NE3,NE4,NE5,NE6”.
- MRTShuttleDirection: str¶
Indicates the direction of free MRT shuttle services available: - “Both”. - towards station name. Example: “Punggol”.
- Message: str¶
Travel advisory notification service for train commuters, published by LTA. This notice is also broadcasted to commuters via the Find-My-Way module in MyTransport mobile app. - Content. - CreatedDate. Example: “1710hrs: NEL - No train service between Harbourfront to Dhoby Ghaut stations towards Punggol station due to a signalling fault. Free bus rides are available at designated bus stops. 2017-12-01 17:54:21”.