Skip to main content

KNMI_Data_Platform

knmidata is a lightweight Python client for the KNMI Data Platform that fetches observational and gridded meteorological data directly into standard xarray.Dataset objects.

Two APIs are supported:

  • Open Data API — bulk NetCDF file archives (e.g. radar composites, in-situ observations), downloaded and assembled into one xarray.Dataset.
  • EDR API — OGC EDR spatio-temporal queries (/collections, /locations, /position, /area, /cube); CoverageJSON/GeoJSON responses are parsed into in-memory xarray.Dataset objects.

Install

pip install knmidata

Authentication

All endpoints require an API key. Request a free key at developer.dataplatform.knmi.nl. KNMI issues a separate key per API — an Open Data key does not work for EDR and vice versa:

export KNMI_OPENDATA_API_KEY="<your open data key>"
export KNMI_EDR_API_KEY="<your edr key>"   # EDR has no anonymous key

For Open Data only, you can omit the key entirely and the public anonymous key is used automatically (shared rate limit).

Usage

Time arguments accept str, pandas.Timestamp, datetime, or date (exported as knmidata.TimeLike); naive values are assumed UTC and normalized to ISO-8601 UTC.

Synchronous client

KNMIClient runs requests on a background event loop, so it works in plain scripts and in environments that already run a loop (e.g. Jupyter):

import knmidata

with knmidata.KNMIClient() as client:
    # Open Data: get files as one dataset (cached on disk if cache_dir is given)
    ds = client.opendata.get_dataset(
        "daily-in-situ-meteorological-observations",
        "1.0",
        start_time="2024-01-01",
        end_time="2024-01-31",
        cache_dir="./data",  # omit to keep the dataset in memory only
        max_files=10,
    )

    # EDR: time series for one station (De Bilt, WSI 0-20000-0-06260)
    ts = client.edr.get_location(
        "daily-in-situ-meteorological-observations",
        "0-20000-0-06260",
        start_time="2026-06-01",
        end_time="2026-06-08",
        parameters=["RH", "TG", "EV24"],  # or a single variable: "TG"
    )
    ts["TG"].plot()  # needs matplotlib

One-liners

The same without keeping a client around:

import knmidata

ds = knmidata.get_dataset(
    "10-minute-in-situ-meteorological-observations",
    "1.0",
    start_time="2024-06-01",
    end_time="2024-06-02",
    cache_dir="./data",
)

ts = knmidata.get_timeseries(
    "daily-in-situ-meteorological-observations",
    "0-20000-0-06260",
    start_time="2026-06-01",
    end_time="2026-06-08",
    parameters="TG",
)

Asynchronous client

The same API is available asynchronously:

import knmidata

async with knmidata.AsyncKNMIClient() as client:
    ds = await client.opendata.get_dataset(
        "daily-in-situ-meteorological-observations", "1.0", ...
    )
    ts = await client.edr.get_location(
        "daily-in-situ-meteorological-observations", "0-20000-0-06260", ...
    )

Lower-level methods

client.opendata also exposes list_files, get_download_url, download_files (API → disk), open_dataset (disk → xr.Dataset), and get_dataset (either). client.edr exposes metadata (collections, collection, instances, locations) and the queries get_location, get_position, get_area, get_cube, plus nearest_location to find a station by coordinates.

See docs/example_daily_in_situ_observations.ipynb for a full walkthrough comparing both APIs.

Documentation

The documentation (example walkthrough and API reference) is built with Sphinx and published to GitHub Pages at artesiawater.github.io/KNMI_Data_Platform.

Development

uv sync --extra dev
uv run pytest            # tests with coverage
uv run ruff check        # lint
uv run ty check src      # type check

This KNMIdata python package was first setup by under macukadam/KNMI_Weather_API who we thank for their initial work. KNMIdata is now maintained by artesia-water.

Metadata

Release files for knmidata 2.0.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 knmidata 2.0.0
File Size Uploaded Provenance Actions
knmidata-2.0.0.tar.gz 55.9 kB Without provenance Details for knmidata-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for knmidata 2.0.0
File Interpreter ABI Platform Actions
knmidata-2.0.0-py3-none-any.whl Python 3 none any Details for knmidata-2.0.0-py3-none-any.whl

Total release size: 93.7 kB

Release files / knmidata-2.0.0.tar.gz

Download URL knmidata-2.0.0.tar.gz
Size 55.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0820b8e76d092fa6552dbf067c0833daae16b0d57c53b2a42a7975215baa9659
BLAKE2b-256 checksum
How to use checksums
4ffe92c6caaeb3a266b526ba4f11944aa4f0384f65882fbb9b42fbb6b1db7740
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / knmidata-2.0.0-py3-none-any.whl

Download URL knmidata-2.0.0-py3-none-any.whl
Size 37.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1b4c5b81b41c725f4bad1bec8bc17686d99aad0dff35a041408029ad0b20bef
BLAKE2b-256 checksum
How to use checksums
13d57ae986781c0b69036a54e7daabade2f6db3536857fd062454e1a2edf5e4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for knmidata 2.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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