Simple DWD Weatherforecast

3.4.1 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Weather` object with a station ID and retrieve current and future temperature forecasts. It also shows how to get the raw weather condition code. Station IDs can be found via `get_nearest_station_id` or from DWD's official lists. All datetime objects passed to the library should be in UTC.

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.")

view raw JSON →