Simple DWD Weatherforecast
Simple DWD Weatherforecast is a Python library (version 3.4.1) providing a straightforward tool to retrieve weather forecasts from DWD (Deutscher Wetterdienst) OpenData. It allows access to hourly forecast data for the next 10 days, reported weather conditions, weather maps from the DWD GeoServer, and air quality measurements and forecasts. The project is actively maintained with frequent updates.
Warnings
- gotcha When fetching hourly data by setting `force_hourly=True`, the library downloads approximately 37MB of data per call. Additionally, this mode may omit some data elements like `PRECIPITATION_PROBABILITY` and `PRECIPITATION_DURATION`.
- gotcha Datetime values provided to library methods must always be in UTC. Providing naive datetimes or datetimes in other timezones can lead to incorrect data retrieval or errors.
- gotcha Weather condition data is returned as a raw digit value provided by DWD. Users are responsible for converting these codes into human-readable conditions, though simplified conversion tables might be available within the library's source code or documentation.
- gotcha Unexpected `ModuleNotFoundError` for `stream_unzip` or `stream_inflate`, or build failures related to these packages, have been reported in certain environments (e.g., Home Assistant, specific Python versions, or beta builds). This indicates dependency resolution issues.
Install
-
pip install simple-dwd-weatherforecast
Imports
- dwdforecast
from simple_dwd_weatherforecast import dwdforecast
- dwdmap
from simple_dwd_weatherforecast import dwdmap
Quickstart
from simple_dwd_weatherforecast import dwdforecast
from datetime import datetime, timezone
# Find nearest Station-ID automatically (uncomment to use)
# id = dwdforecast.get_nearest_station_id(50.1109221, 8.6821267)
# Or use a known Station-ID, e.g., for BERLIN-SCHOENEFELD
station_id = "10385"
dwd_weather = dwdforecast.Weather(station_id)
time_now = datetime.now(timezone.utc)
try:
temperature_now = dwd_weather.get_forecast_data(dwdforecast.WeatherDataType.TEMPERATURE_2M, time_now)
print(f"Temperature at {station_id} ({time_now.isoformat()} UTC): {temperature_now}°C")
# Get a specific forecast for a few hours later
future_time = time_now.replace(hour=(time_now.hour + 3) % 24) # Example: 3 hours later on the same day
future_temp = dwd_weather.get_forecast_data(dwdforecast.WeatherDataType.TEMPERATURE_2M, future_time)
print(f"Temperature at {station_id} ({future_time.isoformat()} UTC): {future_temp}°C")
# Get weather condition (requires manual conversion from digit value if not using helper)
weather_condition_code = dwd_weather.get_forecast_data(dwdforecast.WeatherDataType.WEATHER_CONDITION, time_now)
print(f"Weather condition code: {weather_condition_code}")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure the station ID is valid and DWD data is available for the requested time.")