Skip to main content

pydmi-weather

Install as pydmi-weather, import as pydmi.

Python wrapper for the free Open Data APIs from DMI (Danmarks Meteorologiske Institut).

API Status
Forecast Data EDR API ✅ DMIForecast / DMIForecastAsync
Meteorological Observations API planned (current conditions for the HA weather entity)
  • HARMONIE DINI model: ~2 km grid, hourly steps, ~60 h ahead, new run every 3 hours
  • Sync client: standard library only, thread-safe. Use it in services like WeatherDataLogger.
  • Async client: aiohttp, accepts an injected session. Use it in Home Assistant.
  • Output in normal units (°C, hPa, m/s, mm, %) with unit-suffixed field names
  • Derived Home Assistant condition strings, day/night aware
  • Daily aggregates in your local time zone

No API key is needed. DMI removed authentication from opendataapi.dmi.dk.

Install

pip install pydmi-weather    # sync client, no dependencies
pip install "pydmi-weather[async]"   # + aiohttp for the async client

Usage

from pydmi import DMIForecast, ATTRIBUTION

dmi = DMIForecast(55.64, 12.08)          # lat, lon
fc = dmi.get_forecast()                  # cached for update_interval (30 min)

print(fc.model_run, ATTRIBUTION)
now = fc.current()
print(now.temperature_c, now.condition, now.wind_speed_ms)

for h in fc.hourly()[:6]:
    print(h.datetime, h.temperature_c, h.precipitation_mm, h.condition)

for d in fc.daily():                     # Europe/Copenhagen by default
    print(d.date, d.temperature_min_c, d.temperature_max_c, d.precipitation_mm, d.condition)

payload = fc.to_dict()                   # JSON-ready, e.g. for MQTT

Async:

from pydmi.client_async import DMIForecastAsync

async with DMIForecastAsync(55.64, 12.08, session=session) as dmi:
    fc = await dmi.get_forecast()

See examples/ for an MQTT publisher (WeatherDataLogger style) and a Home Assistant coordinator and weather entity.

Respecting the free service

DMI Open Data is free to use, and the library is built to keep it that way:

What How
Fair use limit (500 req / 5 s, shared by everyone) Responses are cached. update_interval defaults to 30 min and cannot go below 10 min. The model only changes every 3 h anyway.
HTTP 429 The client honours Retry-After. While it waits it returns the cached forecast and does not contact DMI.
Minimal payload One /position request, 13 parameters, CoverageJSON (DMI says it is >10× smaller than GeoJSON), gzip
Cacheable requests Coordinates are rounded to 2 decimals (~1 km, finer than the 2 km grid)
Identification User-Agent: pydmi/<version>
Concurrency A lock makes concurrent callers share one request

Licence: CC BY 4.0, attribution required

DMI's data is licensed under CC BY 4.0. Wherever the data is shown, you must credit DMI. Use pydmi.ATTRIBUTION (fc.attribution). In Home Assistant, set it as _attr_attribution.

Data notes

  • Precipitation: DMI's total-precipitation is accumulated from the start of the run. The library converts it to the amount per hour. precipitation_mm on an hour is the amount expected during that hour (the Home Assistant / met.no convention). The last step is None.
  • Condition: the EDR API has no weather symbol, so one is derived. Priority order: thunder (lightning probability ≥ 30 %; note DMI returns this in percent, although its metadata says 0..1), precipitation (≥ 0.3 mm/h, with rain, snow, sleet or hail taken from precipitation-type), fog (visibility < 1 km), wind (≥ 13.9 m/s), then cloud cover. Night uses clear-night. All thresholds are in const.py.
  • Daily: grouped by local date. Today covers the rest of the day. Later days with fewer than 12 hours (the end of the run) are dropped.
  • Model run: fc.model_run is the first time step of the run (UTC).
  • Chance of precipitation: precipitation_probability_pct (0–100, in steps of 10) is the chance of at least 0.1 mm during the hour. It comes from DMI's ensemble (harmonie_dini_eps_percentiles): the spread of 1-hour precipitation over the ensemble members is read as a distribution, and the chance of exceeding 0.1 mm is interpolated from it. The daily value is the highest hourly chance that day (an approximation). This costs one extra request per update. If it fails, the forecast is still returned, with None here. Turn it off with include_precipitation_probability=False.
  • Current conditions: fc.current() interpolates instantaneous values (temperature, pressure, humidity, wind, cloud cover, radiation) linearly between the two hourly steps around now, so values change smoothly through the hour. Wind direction takes the shortest way around the compass. Precipitation is the amount for the current hour. Use fc.current(interpolate=False) to get the start-of-hour step unchanged.

Development

pip install -e ".[test]"
pytest

The tests use a local mock server, so DMI is never contacted.

Metadata

Release files for pydmi-weather 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydmi-weather 0.3.0
File Size Uploaded Provenance Actions
pydmi_weather-0.3.0.tar.gz 27.6 kB With provenance Details for pydmi_weather-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydmi-weather 0.3.0
File Interpreter ABI Platform Actions
pydmi_weather-0.3.0-py3-none-any.whl Python 3 none any Details for pydmi_weather-0.3.0-py3-none-any.whl

Total release size: 49.2 kB

Release files / pydmi_weather-0.3.0.tar.gz

Download URL pydmi_weather-0.3.0.tar.gz
Size 27.6 kB
Tags Source
SHA-256 checksum
How to use checksums
84eeb5b430a1fa3cfdd393abe7bcc412719dfb23d9c45e05516dd9ee2f2142ba
BLAKE2b-256 checksum
How to use checksums
3f291fba81ea279453d6276e59a033d972725885b57558ae2f029ed43309d074
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / pydmi_weather-0.3.0-py3-none-any.whl

Download URL pydmi_weather-0.3.0-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3136fedccbb5df49bd2800f6ccffd6a940b098eabeff54087eb024208429efb8
BLAKE2b-256 checksum
How to use checksums
fc8c3ef90a1e2a986613b598de18ad8c4d5b96092d9096339dd467e23bcd5aea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for pydmi-weather 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydmi_weather-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page