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

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)

  • cache_backend (str | BaseCache)

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:

BusArrivalDict

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:

list[BusRoutesDict]

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:

list[BusServicesDict]

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:

list[BusStopsDict]

facilities_maintenance() list[FacilitiesMaintenanceDict]

Returns adhoc lift maintenance in MRT stations.

Returns:

Station codes and namse with IDs of lifts being serviced.

Return type:

list[FacilitiesMaintenanceDict]

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:

Url

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:

Url

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:

Url

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:

Url

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:

list[PlannedBusRoutesDict]

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:

list[StationCrowdDensityForecastDict]

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:

list[StationCrowdDensityRealTimeDict]

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:

list[TaxiAvailabilityDict]

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:

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]

Argument Types

class landtransportsg.public_transport.BusArrivalArgsDict

Bases: TypedDict

Type definition for bus_arrival() input arguments

bus_stop_code: str

Bus stop reference code.

Example:

“83139”

service_number: NotRequired[str]

Bus service number.

Example:

“15”

Default:

None

class landtransportsg.public_transport.PassengerVolumeArgsDict

Bases: TypedDict

Type 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

class landtransportsg.public_transport.StationCrowdDensityArgsDict

Bases: TypedDict

Type definition for station_crowd_density_real_time() and station_crowd_density_forecast() input arguments

train_line: str

Code of train network line. Use train_lines() for the list train lines.

Example:

“EWL”

Types

class landtransportsg.public_transport.BusArrivalDict

Bases: TypedDict

Type definition for bus_arrival()

BusStopCode: str

Bus stop reference code.

Example:

“83139”

Services: list[_BusArrivalServiceDict]

Bus services.

class landtransportsg.public_transport._NextBusDict

Bases: TypedDict

Type 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

Load: str | None

Current bus occupancy / crowding level:

  • “SEA” - for Seats Available.

  • “SDA” - for Standing Available.

  • “LSD” - for Limited Standing.

Example:

“SEA”

Feature: str | None

Indicates if bus is wheel-chair accessible:

  • “WAB”.

  • blank.

Example:

“WAB”

Type: str | None

Vehicle type:

  • “SD” - for Single Deck.

  • “DD” - for Double Deck.

  • “BD” - for Bendy.

Example:

“SD”

class landtransportsg.public_transport.BusRoutesDict

Bases: _BusRoutesDict

Type definition for bus_routes()

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

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”

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 | None

Location at which the bus service loops, empty if not a loop service.

Example:

“Raffles Blvd”

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

Bases: TypedDict

Type definition for facilities_maintenance()

Line: str

Code of train network line.

Example:

“NEL”

StationCode: str

Code of trains station.

Example:

“NE12”

StationName: str

Name of trains station.

Example:

“Serangoon”

LiftID: str | None

ID of the lift which is currently under maintenance. This value is optional.

Example:

“B1L01”

LiftDesc: str

Detailed description of the lift which is currently under maintenance.

Example:

“Exit B Street level - Concourse”

class landtransportsg.public_transport.PlannedBusRoutesDict

Bases: _BusRoutesDict

Type definition for planned_bus_routes()

EffectiveDate: date

The date when the new/updated bus routes will take effect.

Example:

date(2025, 3, 2)

class landtransportsg.public_transport.StationCrowdDensityRealTimeDict

Bases: TypedDict

Type definition for station_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.StationCrowdDensityForecastDict

Bases: TypedDict

Type definition for station_crowd_density_forecast()

Date: datetime

Midnight of the forecasted date.

Example:

datetime(2021, 9, 15, 0, 0, 0)

Stations: list[_StationCrowdDensityForecastStationDict]

Array of station crowd density forecast.

class landtransportsg.public_transport._StationCrowdDensityForecastStationDict

Bases: TypedDict

Type definition for StationCrowdDensityForecastDict

Station: str

Station code.

Example:

“EW13”

Interval: list[_StationCrowdDensityForecastStationIntervalDict]

Array of station crowd density forecast per time interval.

class landtransportsg.public_transport._StationCrowdDensityForecastStationIntervalDict

Bases: TypedDict

Type definition for StationCrowdDensityForecastStationDict

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

AffectedSegments: list[_TrainServiceAlertAffectedSegmentDict]

Array of train servicee affected segments.

landtransportsg.public_transport.Url

alias of str