datagovsg_api API Reference

Visit the Github repo at half0wl/datagovsg_api for installation, usage, and examples.

class datagovsg_api.DataGovSG(API_KEY)[source]

Base class for API wrappers to inherit from.

Parameters:API_KEY (str) – A valid API key obtained from developers.data.gov.sg.
build_url(endpoint)[source]

Build the request url.

Parameters:endpoint (str) – Endpoint of the request (e.g. ‘environment/psi’).
Returns:The built/final URL to the endpoint.
Return type:str
get(endpoint, params)[source]

Base method for making requests to the API endpoint.

Parameters:
  • endpoint (str) – Endpoint of the request (e.g. ‘environment/psi’).
  • params (dict, optional) – Request parameters.
Returns:

A Response object.

class datagovsg_api.TransportAPI(API_KEY)[source]

https://developers.data.gov.sg/transport/

This class contains APIs under the Transport category.

Parameters:API_KEY (str) – A valid API key obtained from developers.data.gov.sg.
taxi_availability(date_time=None)[source]

https://developers.data.gov.sg/transport/taxi-availability

List of all available taxis, retrieved every 30 seconds from LTA’s Datamall.

Parameters:date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:A Response object. Call .json() to get the json data. The returned json of this method is valid GeoJSON.
traffic_images(date_time=None)[source]

https://developers.data.gov.sg/transport/traffic-images

Images from traffic cams with camera location. Retrieved every 20 seconds from LTA’s Datamall.

Parameters:date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:A Response object. Call .json() to get the json data.
class datagovsg_api.EnvironmentAPI(API_KEY)[source]

https://developers.data.gov.sg/environment/

This class contains APIs under the Environment category.

Parameters:API_KEY (str) – A valid API key obtained from developers.data.gov.sg.
air_temperature(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/air-temperature

Air temperature readings across Singapore. Per-minute readings from NEA.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data.

pm25(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/pm25

PM2.5 readings across Singapore. Retrieved hourly from NEA.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data. The region_metadata field in the response contains the lat/lon for the regions.

psi(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/psi

PSI readings across Singapore. Retrieved hourly from NEA.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data. The region_metadata field in the response contains the lat/lon for the regions.

rainfall(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/rainfall

Rainfall readings across Singapore. 5-minute readings from NEA.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data.

relative_humidity(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/relative_humidity

Relative humidity readings across Singapore. Per-minute readings from NEA.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data.

uv_index(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/uv-index

UV index readings across Singapore. Retrieved every hour between 7AM and 7PM everyday.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data.

weather_forecast(duration, date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/2-hour-weather-forecast https://developers.data.gov.sg/environment/24-hour-weather-forecast https://developers.data.gov.sg/environment/4-day-weather-forecast

Weather forecast. 2-hour forecast is retrieved half-hourly from NEA, 24-hour is retrieved multiple times throughout the day, and 4-day is retrieved twice a day from NEA.

Parameters:
  • duration (str) – The duration to retrieve: '2-hour', '24-hour', '4-day'.
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data.

Raises:

Exception – Duration must be a string ‘2-hour’, ‘24-hour’, ‘4-day’.

wind_direction(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/wind-direction

Wind direction readings readings across Singapore. Per-minute readings from NEA.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data.

wind_speed(date=None, date_time=None)[source]

https://developers.data.gov.sg/environment/wind-speed

Wind speed readings across Singapore. Per-minute readings from NEA.

Parameters:
  • date (str, optional) – All data on that day. Use the format YYYY-MM-DD, for example: 2016-12-12.
  • date_time (str, optional) – Latest available data at that moment in time. Use the format YYYY-MM-DD[T]HH:mm:ss (SGT), for example: 2016-12-12T09:45:00.
Returns:

A Response object. Call .json() to get the json data.

class datagovsg_api.AllAPI(API_KEY)[source]

This class exposes all available APIs, so a single instance can access both Transport and Environment APIs.

Parameters:API_KEY (str) – A valid API key obtained from developers.data.gov.sg.