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.
pip install simple-dwd-weatherforecastVerified import paths — ran on the pinned version, not inferred.
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.
Be mindful of network usage and data completeness when using `force_hourly=True`. Consider if these specific elements are critical for your application.
Always use `datetime.now(timezone.utc)` or ensure any `datetime` objects are explicitly set to UTC before passing them to `simple-dwd-weatherforecast` functions.
Implement a mapping or use an existing utility (if provided by the library) to convert the numerical weather condition codes into descriptive strings.
Ensure that `stream-unzip` and `stream-inflate` are correctly installed and compatible with your Python version. Sometimes, upgrading `simple-dwd-weatherforecast` to its latest version (which might include updated dependency specifications) or manually installing specific versions of `stream-unzip`/`stream-inflate` can resolve the issue.
Install the library using pip: `pip install simple-dwd-weatherforecast`
Always check if the result of `get_forecast_data()` is not `None` before attempting to access its contents:
```python
from simple_dwd_weatherforecast import DwdWeatherForecast
dwd_weather = DwdWeatherForecast("10865") # Example station ID
forecast_data = dwd_weather.get_forecast_data()
if forecast_data:
print(forecast_data.keys())
else:
print("Failed to retrieve forecast data or no data available.")
```Verify the station ID is correct and active. Use `DwdWeatherForecast.get_stations()` to find valid station IDs and their available data types:
```python
from simple_dwd_weatherforecast import DwdWeatherForecast
# Find valid stations
stations = DwdWeatherForecast.get_stations()
for station_id, station_info in stations.items():
if "description" in station_info and "Hamburg-Fuhlsbuettel" in station_info["description"]:
print(f"Found Hamburg-Fuhlsbuettel: {station_id}")
# Use a verified station ID
dwd_weather = DwdWeatherForecast("10147") # Example of a valid ID
forecast_data = dwd_weather.get_forecast_data()
```Check the available keys using `forecast_data.keys()` or `dwd_weather.get_forecast_keys()` to ensure you are requesting a valid parameter name:
```python
from simple_dwd_weatherforecast import DwdWeatherForecast
dwd_weather = DwdWeatherForecast("10865")
forecast_data = dwd_weather.get_forecast_data()
if forecast_data:
# Option 1: Check available keys dynamically
print("Available keys:", forecast_data.keys())
if 'temperature_air_2m' in forecast_data: # A common valid key
print(f"2m Air Temperature: {forecast_data['temperature_air_2m']}")
else:
print("Specific key not found in data.")
# Option 2: Get all possible forecast keys for the library
all_possible_keys = dwd_weather.get_forecast_keys()
print("All possible forecast keys:", all_possible_keys)
```