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: Lta

Interact 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:
  • bus_stop_code (str) – 5-digit bus stop reference code.

  • service_number (str) – Bus service number. If omitted, then all bus services at the bus stop code are returned. Defaults to None.

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:

BusArrivalDict

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:

list[BusRoutesDict]

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:

list[BusServicesDict]

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:

list[BusStopsDict]

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:

list[PlatformCrowdDensityForecastDict]

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:

list[PlatformCrowdDensityRealTimeDict]

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:

list[TaxiAvailabilityDict]

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:

list[TaxiStandsDict]

train_lines() tuple[str, ...]

Return the tuple of valid train lines.

Returns:

Tuple of valid train lines.

Return type:

tuple[str, …]

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:

list[TrainServiceAlertsDict]

Types

class landtransportsg.public_transport.BusArrivalDict

Bases: TypedDict

Type definition for bus_arrival()

ServiceNo: str

Bus service number. Example: “15”.

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: TypedDict

Type 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”.

Load: str

Current bus occupancy / crowding level: - “SEA” - for Seats Available. - “SDA” - for Standing Available. - “LSD” - for Limited Standing. Example: “SEA”.

Feature: str

Indicates if bus is wheel-chair accessible: - “WAB”. - blank. Example: “WAB”.

Type: str

Vehicle type: - “SD” - for Single Deck. - “DD” - for Double Deck. - “BD” - for Bendy. Example: “SD”.

class landtransportsg.public_transport.BusServicesDict

Bases: TypedDict

Type definition for bus_services()

ServiceNo: str

The bus service number. Example: “107M”.

Operator: str

Operator for this bus service. Example: “SBST”.

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

OriginCode: str

Bus stop code for first bus stop. Example: “64009”.

DestinationCode: str

Bus stop code for last bus stop (similar as first stop for loop services). Example: “64009”.

AM_Peak_Freq: str

Freq of dispatch for AM Peak 0630H - 0830H (range in minutes). Example: “5-08”.

AM_Offpeak_Freq: str

Freq of dispatch for AM Off-Peak 0831H - 1659H (range in minutes). Example: “10-16”.

PM_Peak_Freq: str

Freq of dispatch for PM Peak 1700H - 1900H (range in minutes). Example: “8-10”.

PM_Offpeak_Freq: str

Freq of dispatch for PM Off-Peak after 1900H (range in minutes). Example: “12-15”.

LoopDesc: str

Location at which the bus service loops, empty if not a loop service. Example: “Raffles Blvd”.

class landtransportsg.public_transport.BusRoutesDict

Bases: TypedDict

Type definition for bus_routes()

ServiceNo: str

The bus service number. Example: “107M”.

Operator: str

Operator for this bus service. Example: “SBST”.

Direction: int

The direction in which the bus travels (1 or 2), loop services only have 1 direction. Example: 1.

StopSequence: int

The i-th bus stop for this route. Example: 28.

BusStopCode: str

The unique 5-digit identifier for this physical bus stop. Example: “01219”.

Distance: float

Distance travelled by bus from starting location to this bus stop (in kilometres). Example: 10.3.

WD_FirstBus: str

Scheduled arrival of first bus on weekdays. Example: “2025”.

WD_LastBus: str

Scheduled arrival of last bus on weekdays. Example: “2352”.

SAT_FirstBus: str

Scheduled arrival of first bus on Saturdays. Example: “1427”.

SAT_LastBus: str

Scheduled arrival of last bus on Saturdays. Example: “2349”.

SUN_FirstBus: str

Scheduled arrival of first bus on Sundays. Example: “0620”.

SUN_LastBus: str

Scheduled arrival of last bus on Sundays. Example: “2349”.

class landtransportsg.public_transport.BusStopsDict

Bases: TypedDict

Type definition for bus_stops()

BusStopCode: str

The unique 5-digit identifier for this physical bus stop. Example: “01219”.

RoadName: str

The road on which this bus stop is located. Example: “Victoria St”.

Description: str

Landmarks next to the bus stop (if any) to aid in identifying this bus stop. Example: “Hotel Grand Pacific”.

Latitude: float

Latitude location coordinates for this bus stop. Example: 1.29685.

Longitude: float

Latitude location coordinates for this bus stop. Example: 103.853.

class landtransportsg.public_transport.PlatformCrowdDensityRealTimeDict

Bases: TypedDict

Type definition for platform_crowd_density_real_time()

Station: str

Station code. Example: “EW13”.

StartTime: datetime

The start of the time interval. Example: datetime(2021, 9, 15, 9, 40, 0).

EndTime: datetime

The end of the time interval. Example: datetime(2021, 9, 15, 9, 50, 0).

CrowdLevel: str

The crowdedness level indicates: - “l” - low. - “h” - high. - “m” - moderate. - blank. Example: “l”.

class landtransportsg.public_transport.PlatformCrowdDensityForecastDict

Bases: TypedDict

Type definition for platform_crowd_density_forecast()

Date: datetime

Midnight of the forecasted date. Example: datetime(2021, 9, 15, 0, 0, 0).

Stations: list[_PlatformCrowdDensityForecastStationDict]

Array of platform crowd density forecast per station.

class landtransportsg.public_transport._PlatformCrowdDensityForecastStationDict

Bases: TypedDict

Type definition for PlatformCrowdDensityForecastDict

Station: str

Station code. Example: “EW13”.

Interval: list[_PlatformCrowdDensityForecastStationIntervalDict]

Array of platform crowd density forecast per station per time interval.

class landtransportsg.public_transport._PlatformCrowdDensityForecastStationIntervalDict

Bases: TypedDict

Type definition for PlatformCrowdDensityForecastStationDict

Start: datetime

The start of the time interval. Example: datetime(2021, 9, 15, 0, 0, 0).

CrowdLevel: str

The crowdedness level indicates: - “l” - low. - “h” - high. - “m” - moderate. - blank. Example: “l”.

class landtransportsg.public_transport.TaxiAvailabilityDict

Bases: TypedDict

Type definition for taxi_availability()

Latitude: float

Latitude location coordinates. Example: 1.35667.

Longitude: float

Longitude location coordinates. Example: 103.93314.

class landtransportsg.public_transport.TaxiStandsDict

Bases: TypedDict

Type definition for taxi_stands()

TaxiCode: str

Code representation of Taxi facility. Example: “A01”.

Latitude: float

Latitude map coordinates for the taxi stand. Example: 1.303980684.

Longitude: float

Longitude map coordinates for the taxi stand. Example: 103.9191828.

Bfa: str

Indicate whether the Taxi stand is barrier free. Example: “Yes”.

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”.

Type: str

Indicate the type of the Taxi stand. - “Stand” - allows Taxis to queue in the taxi bays and wait for passengers. - “Stop” - allow Taxis to perform immediate pick up and drop off of passengers. Example: “Stand”.

Name: str

Name of Taxi facility. Example: “Orchard Rd along driveway of Lucky Plaza”.

class landtransportsg.public_transport.TrainServiceAlertsDict

Bases: TypedDict

Type 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”.

landtransportsg.public_transport.Url

alias of str