datagovsg.environment¶
Client for interacting with the Environment APIs.
Example usage:
# get the latest lightning observations
from datagovsg import Environment
from datagovsg.environment.types import WeatherDict
environment = Environment()
lightning: WeatherDict = environment.lightning()
Methods¶
- class datagovsg.environment.client.Client(api_key: str | None = None, cache_backend: str | BaseCache = 'sqlite')¶
Bases:
DataGovSgInteract with the environment-related endpoints.
Reference: https://data.gov.sg/datasets?formats=API&topics=environment
- air_temperature(**kwargs: Unpack[EnvironmentArgsDict]) EnvironmentReadingDict¶
Get air temperature readings across Singapore.
Has per-minute readings from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 May 2016 12:00am (inclusive).- Returns:
Air Temperature Information. (Cached for 1 minute.)
- Return type:
- flood_alerts(**kwargs: Unpack[EnvironmentArgsDict]) WeatherDict¶
Get flood alert information across Singapore.
Update frequency is not specified, so defaults to half hourly.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Returns:
Flood alert Information. (Cached for 30 minutse.)
- Return type:
- four_day_weather_forecast(**kwargs: Unpack[EnvironmentArgsDict]) WeatherForecastFourDayDict¶
Retrieve the latest 4 day weather forecast.
Updated twice a day from NEA. The forecast is for the next 4 days.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 March 2016 12:00am (inclusive).- Returns:
4 Day Weather Forecast. (Cached for 12 hours.)
- Return type:
- lightning(**kwargs: Unpack[WeatherArgsDict]) WeatherDict¶
Retrieve the latest lightning observation.
Update frequency is not specified, so defaults to half hourly.
- Parameters:
kwargs (WeatherArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 February 2025 12:00am (inclusive).- Returns:
Lightning Information. (Cached for 30 minutse.)
- Return type:
- pm25(**kwargs: Unpack[EnvironmentArgsDict]) PM25Dict¶
Retrieve the latest PM2.5 information in Singapore.
Updated hourly from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 February 2016 12:00am (inclusive).- Returns:
PM 2.5 Information. (Cached for 1 hour.)
- Return type:
- psi(**kwargs: Unpack[EnvironmentArgsDict]) PSIDict¶
Retrieve the latest PSI information in Singapore.
Updated hourly from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 February 2016 12:00am (inclusive).- Returns:
PSI Information. (Cached for 1 hour.)
- Return type:
- rainfall(**kwargs: Unpack[EnvironmentArgsDict]) EnvironmentReadingDict¶
Get rainfall readings across Singapore.
5-minute readings from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 December 2016 12:00am (inclusive).- Returns:
Rainfall Information. (Cached for 5 minutes.)
- Return type:
- relative_humidity(**kwargs: Unpack[EnvironmentArgsDict]) EnvironmentReadingDict¶
Get relative humidity readings.
Has per-minute readings from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 November 2016 12:00am (inclusive).- Returns:
Relative Humidity Information. (Cached for 1 minute.)
- Return type:
- twenty_four_hour_weather_forecast(**kwargs: Unpack[EnvironmentArgsDict]) WeatherForecastTwentyFourHourDict¶
Retrieve the latest 24 hour weather forecast.
Updated multiple times throughout the day.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 March 2016 12:00am (inclusive).- Returns:
24 Hour Weather Forecast. (Cached for 1 hour.)
- Return type:
- two_hour_weather_forecast(**kwargs: Unpack[EnvironmentArgsDict]) WeatherForecastTwoHourDict¶
Retrieve the latest two hour weather forecast.
Updated half-hourly from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 March 2016 12:00am (inclusive).- Returns:
2 Hour Weather Forecast. (Cached for 30 minutes.)
- Return type:
- uv_index(**kwargs: Unpack[EnvironmentArgsDict]) UVIndexDict¶
Retrieve the latest UV index information in Singapore.
Updated every hour between 7 AM and 7 PM everyday. The UV index value is averaged over the preceding hour.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 March 2016 12:00am (inclusive).- Returns:
UV Index Information. (Cached for 1 hour.)
- Return type:
- wbgt(**kwargs: Unpack[WeatherArgsDict]) WeatherDict¶
Retrieve the latest WBGT data for accurate heat stress assessment.
Update frequency is not specified, so defaults to half hourly.
- Parameters:
kwargs (WeatherArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 February 2025 12:00am (inclusive).- Returns:
Wet Bulb Globe Temperature Information. (Cached for 30 minutse.)
- Return type:
- wind_direction(**kwargs: Unpack[EnvironmentArgsDict]) EnvironmentReadingDict¶
Get wind direction readings across Singapore.
Has per-minute readings from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 November 2016 12:00am (inclusive).- Returns:
Wind Direction Information. (Cached for 1 minute.)
- Return type:
- wind_speed(**kwargs: Unpack[EnvironmentArgsDict]) EnvironmentReadingDict¶
Get wind speed readings across Singapore.
Has per-minute readings from NEA.
- Parameters:
kwargs (EnvironmentArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
ValueError –
dateargument is before 1 December 2016 12:00am (inclusive).- Returns:
Wind Speed Information. (Cached for 1 minute.)
- Return type: