weather.client.WeatherClient(latitude, longitude)
Client for fetching weather data from Open-Meteo API. Handles the low-level API interactions, parameter building, and response parsing.
Parameters
| latitude |
float |
Latitude of the location. |
required |
| longitude |
float |
Longitude of the location. |
required |
Examples
import pandas as pd
from spotforecast2_safe.weather import WeatherClient
client = WeatherClient(latitude=52.52, longitude=13.405)
df = client.fetch_archive(
start=pd.Timestamp("2023-01-01", tz="UTC"),
end=pd.Timestamp("2023-01-02", tz="UTC"),
)
print(df.head())
temperature_2m relative_humidity_2m precipitation \
datetime
2023-01-01 00:00:00 15.2 59 0.0
2023-01-01 01:00:00 15.6 55 0.0
2023-01-01 02:00:00 15.7 52 0.0
2023-01-01 03:00:00 15.8 51 0.0
2023-01-01 04:00:00 15.8 49 0.0
rain snowfall weather_code pressure_msl \
datetime
2023-01-01 00:00:00 0.0 0.0 3 1010.8
2023-01-01 01:00:00 0.0 0.0 3 1010.9
2023-01-01 02:00:00 0.0 0.0 3 1011.3
2023-01-01 03:00:00 0.0 0.0 3 1011.3
2023-01-01 04:00:00 0.0 0.0 3 1011.5
surface_pressure cloud_cover cloud_cover_low \
datetime
2023-01-01 00:00:00 1006.4 100 0
2023-01-01 01:00:00 1006.5 100 12
2023-01-01 02:00:00 1006.9 100 8
2023-01-01 03:00:00 1006.9 100 1
2023-01-01 04:00:00 1007.1 85 0
cloud_cover_mid cloud_cover_high wind_speed_10m \
datetime
2023-01-01 00:00:00 14 100 30.5
2023-01-01 01:00:00 76 100 30.7
2023-01-01 02:00:00 25 100 31.3
2023-01-01 03:00:00 100 97 28.4
2023-01-01 04:00:00 32 78 28.3
wind_direction_10m wind_gusts_10m
datetime
2023-01-01 00:00:00 232 49.7
2023-01-01 01:00:00 231 52.2
2023-01-01 02:00:00 232 52.2
2023-01-01 03:00:00 231 52.2
2023-01-01 04:00:00 223 47.9
Methods
fetch_archive
weather.client.WeatherClient.fetch_archive(start, end, timezone='UTC')
Fetch historical data from Archive API.
Parameters
| start |
pd.Timestamp |
Start date for the historical data. |
required |
| end |
pd.Timestamp |
End date for the historical data. |
required |
| timezone |
str |
Timezone for the data (default “UTC”). |
'UTC' |
Examples
import pandas as pd
from spotforecast2_safe.weather import WeatherClient
client = WeatherClient(latitude=52.52, longitude=13.405)
df = client.fetch_archive(
start=pd.Timestamp("2023-01-01", tz="UTC"),
end=pd.Timestamp("2023-01-02", tz="UTC"),
)
print(df.head())
temperature_2m relative_humidity_2m precipitation \
datetime
2023-01-01 00:00:00 15.2 59 0.0
2023-01-01 01:00:00 15.6 55 0.0
2023-01-01 02:00:00 15.7 52 0.0
2023-01-01 03:00:00 15.8 51 0.0
2023-01-01 04:00:00 15.8 49 0.0
rain snowfall weather_code pressure_msl \
datetime
2023-01-01 00:00:00 0.0 0.0 3 1010.8
2023-01-01 01:00:00 0.0 0.0 3 1010.9
2023-01-01 02:00:00 0.0 0.0 3 1011.3
2023-01-01 03:00:00 0.0 0.0 3 1011.3
2023-01-01 04:00:00 0.0 0.0 3 1011.5
surface_pressure cloud_cover cloud_cover_low \
datetime
2023-01-01 00:00:00 1006.4 100 0
2023-01-01 01:00:00 1006.5 100 12
2023-01-01 02:00:00 1006.9 100 8
2023-01-01 03:00:00 1006.9 100 1
2023-01-01 04:00:00 1007.1 85 0
cloud_cover_mid cloud_cover_high wind_speed_10m \
datetime
2023-01-01 00:00:00 14 100 30.5
2023-01-01 01:00:00 76 100 30.7
2023-01-01 02:00:00 25 100 31.3
2023-01-01 03:00:00 100 97 28.4
2023-01-01 04:00:00 32 78 28.3
wind_direction_10m wind_gusts_10m
datetime
2023-01-01 00:00:00 232 49.7
2023-01-01 01:00:00 231 52.2
2023-01-01 02:00:00 232 52.2
2023-01-01 03:00:00 231 52.2
2023-01-01 04:00:00 223 47.9
fetch_forecast
weather.client.WeatherClient.fetch_forecast(days_ahead, timezone='UTC')
Fetch forecast data from Forecast API.
Parameters
| days_ahead |
int |
Number of days ahead for the forecast. |
required |
| timezone |
str |
Timezone for the data (default “UTC”). |
'UTC' |
Examples
from spotforecast2_safe.weather import WeatherClient
client = WeatherClient(latitude=52.52, longitude=13.405)
df = client.fetch_forecast(days_ahead=7)
print(df.head())
temperature_2m relative_humidity_2m precipitation \
datetime
2026-05-19 00:00:00 11.1 71 0.0
2026-05-19 01:00:00 10.5 75 0.0
2026-05-19 02:00:00 10.2 76 0.0
2026-05-19 03:00:00 10.1 75 0.0
2026-05-19 04:00:00 10.1 75 0.0
rain snowfall weather_code pressure_msl \
datetime
2026-05-19 00:00:00 0.0 0.0 1 1016.4
2026-05-19 01:00:00 0.0 0.0 1 1015.9
2026-05-19 02:00:00 0.0 0.0 3 1016.2
2026-05-19 03:00:00 0.0 0.0 3 1016.2
2026-05-19 04:00:00 0.0 0.0 3 1016.4
surface_pressure cloud_cover cloud_cover_low \
datetime
2026-05-19 00:00:00 1011.9 29 0
2026-05-19 01:00:00 1011.4 40 0
2026-05-19 02:00:00 1011.7 91 0
2026-05-19 03:00:00 1011.7 93 5
2026-05-19 04:00:00 1011.9 93 13
cloud_cover_mid cloud_cover_high wind_speed_10m \
datetime
2026-05-19 00:00:00 29 0 6.6
2026-05-19 01:00:00 40 0 6.9
2026-05-19 02:00:00 91 0 5.5
2026-05-19 03:00:00 90 0 6.5
2026-05-19 04:00:00 88 0 2.3
wind_direction_10m wind_gusts_10m
datetime
2026-05-19 00:00:00 112 19.4
2026-05-19 01:00:00 99 14.4
2026-05-19 02:00:00 113 14.4
2026-05-19 03:00:00 109 13.7
2026-05-19 04:00:00 162 13.7