landtransportsg: interact with LTA DataMall’s API¶
Release v1.3.0.
This is an unofficial Python package for interacting with APIs available at LTA DataMall.
Using the package¶
Pre-requisite:
API key. Request for API access.
The main steps are:
Import a class.
Instantiate an object from the class.
Call a function on that object.
Refer to any of the modules’ documentation for specific examples.
Contents¶
Package Overview¶
Interacting with LTA DataMall’s API is done through one of three clients, where each client corresponds with a set of endpoints.
The four clients are: ActiveMobility
, Geospatial
, PublicTransport
and Traffic
.
Each client contains several public functions, one function per endpoint. A function’s name is the same as its corresponding endpoint’s ending path.
Some functions accept named arguments, where an argument corresponds with a parameter that the endpoint accepts.
Why have separate clients instead of one single client?
Without knowing how LTA DataMall’s API will evolve, and noticing that the endpoints were themselves already partitioned into sets, it seemed like a good idea to keep each set of endpoints in its own contextual client. This allows for each set of endpoints to be customised on their own, e.g. the
PublicTransport
passenger volume-related endpoints allow for a string to be returned, whereas the other endpoints return a list.
Package Reference¶
landtransportsg¶
Module contents¶
-
landtransportsg.
ActiveMobility
¶
-
landtransportsg.
Geospatial
¶
-
landtransportsg.
PublicTransport
¶
-
landtransportsg.
Traffic
¶
landtransportsg.exceptions¶
Exceptions that could occur when interacting with any API endpoint.
landtransportsg.active_mobility¶
Client for interacting with the Active Mobility API endpoints.
Example usage:
# get the bicycle parking locations
from landtransportsg import ActiveMobility
client = ActiveMobility(API_KEY)
bicycle_parking_locations = client.bicycle_parking(1.364897, 103.766094)
Methods¶
-
class
landtransportsg.active_mobility.client.
Client
(account_key)¶ Bases:
landtransportsg.client.__Client
Interact with the active mobility-related endpoints.
References
https://www.mytransport.sg/content/dam/datamall/datasets/LTA_DataMall_API_User_Guide.pdf
-
bicycle_parking
(latitude, longitude, distance=0.5)¶ Get bicycle parking locations within a radius.
- Parameters
- Returns
(list) Available bicycle parking locations at the specified location.
- Raises
ValueError – If latitude, longitude or distance are not floats.
-
landtransportsg.geospatial¶
Client for interacting with the Geospatial API endpoints.
Example usage:
# get a geospatial whole island layer
from landtransportsg import Geospatial
client = Geospatial(API_KEY)
geospatial_whole_island = client.geospatial_whole_island('ArrowMarking')
Methods¶
-
class
landtransportsg.geospatial.client.
Client
(account_key)¶ Bases:
landtransportsg.client.__Client
Interact with the geospatial-related endpoints.
References
https://www.mytransport.sg/content/dam/datamall/datasets/LTA_DataMall_API_User_Guide.pdf
-
geospatial_whole_island
(geospatial_layer_id)¶ Get the SHP files of the requested geospatial layer.
- Parameters
geospatial_layer_id (str) – Name of geospatial layer. Refer to the GEOSPATIAL_WHOLE_ISLAND_LAYER_IDS constant for the list of valid names.
- Returns
(str) Link for downloading the requested SHP file.
- Raises
ValueError – Raised if geospatial_layer_id is not specified.
ValueError – Raised if geospatial_layer_id is not a string.
ValueError – Raised if geospatial_layer_id is not a valid ID.
-
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
- 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.
-
landtransportsg.traffic¶
Client for interacting with the Traffic API endpoints.
Example usage:
# get the list of available car park spaces
from landtransportsg import Traffic
client = Traffic(API_KEY)
patents = client.carpark_availability()
Methods¶
-
class
landtransportsg.traffic.client.
Client
(account_key)¶ Bases:
landtransportsg.client.__Client
Interact with the traffic-related endpoints.
References
https://www.mytransport.sg/content/dam/datamall/datasets/LTA_DataMall_API_User_Guide.pdf
-
carpark_availability
()¶ Get number of available lots from HDB, LTA and URA carpark data.
- Returns
(list) Available carpark lots.
-
erp_rates
()¶ Get ERP rates of all vehicle types across all timings for each zone.
- Returns
(list) ERP rates per vehicle type by zones.
-
estimated_travel_times
()¶ Get estimated travel times of expressways (in segments).
- Returns
(list) Expressway estimated travel times by segments.
-
faulty_traffic_lights
()¶ Get alerts of traffic lights that are currently faulty, or currently undergoing scheduled maintenance.
- Returns
(list) Traffic light alerts and their status.
-
road_openings
()¶ Get all planned road openings.
- Returns
(list) Road openings for road works.
-
road_works
()¶ Get all road works being / to be carried out.
- Returns
(list) Road works that are being / to be carried out.
-
traffic_images
()¶ Get links to images of live traffic conditions along expressways and Woodlands & Tuas Checkpoints.
- Returns
(list) Traffic images at expressways and checkpoints.
-
traffic_incidents
()¶ Get incidents currently happening on the roads, such as Accidents, Vehicle Breakdowns, Road Blocks, Traffic Diversions etc.
- Returns
(list) Traffic incidents currently happening.
-
traffic_speed_bands
()¶ Get current traffic speeds on expressways and arterial roads, expressed in speed bands.
- Returns
(list) Traffic speed bands on expressways and arterial roads.
-
vms
()¶ Get traffic advisories (via variable message services) concerning current traffic conditions that are displayed on EMAS signboards along expressways and arterial roads.
- Returns
(list) Traffic advisories for expressways and arterial roads.
-
External References¶
Indices and tables¶
License¶
This project is licensed under the GNU General Public License v3.0.
Logo¶
The logo is copyright by the Land Transport Authority, Singapore. It is used for reference only. This project’s owner does not have any copyright claim over it.