landtransportsg.public_transport

Client for interacting with the Public Transport API endpoints.

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.Client(account_key)

Bases: landtransportsg.client.__Client

Interact with the public transport-related endpoints.

References

https://www.mytransport.sg/content/dam/datamall/datasets/LTA_DataMall_API_User_Guide.pdf

bus_arrival(bus_stop_code, service_number=None)

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) – (optional) Bus service number. If omitted, then all bus services at the bus stop code are returned.

Returns

(list) Information about bus arrival at the specified bus stop.

Raises
  • ValueError – Raised if bus_stop_code or service_number are not strings.

  • ValueError – Raised if bus_stop_code is not exactly 5 characters long.

  • ValueError – Raised if bus_stop_code is not a number-like string.

bus_routes()

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

(list) Information about bus routes currently in operation.

bus_services()

Get detailed service information for all buses currently in operation, including: first stop, last stop, peak / offpeak frequency of dispatch.

Returns

(list) Information about bus services currently in operation.

bus_stops()

Get detailed information for all bus stops currently being serviced by buses, including: Bus Stop Code, location coordinate.

Returns

(list) Location coordinaties of bus stops with active services.

facilities_maintenance(station_code)

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. Refer to the STATION_CODES_REGEX_PATTERN constant for the expected regex pattern that this code has to match.

Returns

(str) Link for downloading the requested JSON file.

Raises
  • ValueError – Raised if station_code is not specified.

  • ValueError – Raised if station_code is not a string.

  • ValueError – Raised if station_code does not match the expected regex pattern.

passenger_volume_by_bus_stops(dt=None)

Get tap in and tap out passenger volume by weekdays and weekends for individual bus stop.

Parameters

dt (date) – (optional) 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.

Returns

(str) Download link of file containing passenger volume data.

passenger_volume_by_origin_destination_bus_stops(dt=None)

Get number of trips by weekdays and weekends from origin to destination bus stops.

Parameters

dt (date) – (optional) 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.

Returns

(str) Download link of file containing passenger volume data.

passenger_volume_by_origin_destination_train_stations(dt=None)

Get number of trips by weekdays and weekends from origin to destination train stations.

Parameters

dt (date) – (optional) 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. Default: None, i.e. today.

Returns

(str) Download link of file containing passenger volume data.

passenger_volume_by_train_stations(dt=None)

Get tap in and tap out passenger volume by weekdays and weekends for individual train station.

Parameters

dt (date) – (optional) 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.

Returns

(str) Download link of file containing passenger volume data.

taxi_availability()

Get location coordinates of all Taxis that are currently available for hire. Does not include “Hired” or “Busy” Taxis.

Returns

(list) Location coordinaties of available taxis.

taxi_stands()

Get detailed information of Taxi stands, such as location and whether is it barrier free.

Returns

(list) Detailed information of taxi stands .

train_service_alerts()

Get detailed information on train service unavailability during scheduled operating hours, such as affected line and stations etc.

Returns

(list) Information about train service unavailability.