Locationforecast: API Reference#

class yr_weather.Locationforecast(headers: dict, use_cache: bool | None = True)#

Bases: BaseClient

A client for interacting with the Yr Locationforecast API.

The client has multiple functions which can be used for retrieving data from the API.

It must be initialized with a headers dict, which at least includes a User-Agent. The headers will be used with the requests library.

Example 1. Getting a location forecast for a specified location:

import yr_weather

headers = {
    "User-Agent": "Your User-Agent"
}

yr_client = yr_weather.Locationforecast(headers=headers)

# Get weather data for Oslo, Norway.
weather_data = yr_client.get_forecast(59.91, 10.75)
get_air_temperature(lat: float, lon: float, altitude: int | None = None) float#

Retrieve the air temperature at a given location.

This function returns the latest data available, meaning it provides the current air temperature.

Parameters:
  • lat (float | int) – The latitude of the location.

  • lon (float | int) – The longitude of the location.

  • altitude (Optional[int]) – The altitude of the location, given in whole meters.

Returns:

The air temperature, given in the current scale used by the Yr Locationforecast API (this is usually degrees Celsius).

Return type:

float

get_forecast(lat: float, lon: float, forecast_type: Literal['complete', 'compact'] | None = 'complete') CompleteForecast | CompactForecast#

Retrieve a complete or compact forecast for a selected location.

Parameters:
  • lat (float | int) – The latitude of the location.

  • lon (float | int) – The longitude of the location.

  • forecast_type (Optional[Literal["complete", "compact"]]) – Optionally specify the type of forecast. Possible values: "complete" or "compact".

Returns:

An object with all possible values from the API, including temperature, air pressure, humidity and so on.

Return type:

CompleteForecast | CompactForecast

get_instant_data(lat: float, lon: float, altitude: int | None = None) CompactInstantDetails#

Retrieve current weather information about a location.

This includes air pressure, temperature, humidity, wind and more.

Parameters:
  • lat (float | int) – The latitude of the location.

  • lon (float | int) – The longitude of the location.

  • altitude (Optional[int]) – The altitude of the location, given in whole meters.

Returns:

A typed dict with data received from the API.

Return type:

CompactInstantDetails

get_units() CompleteUnits#

Retrieve a list of units used by the Yr Locationforecast API.

Returns:

A typed dict with units currently used.

Return type:

CompleteUnits