Skip to main content

OGC Environmental Data Retrieval (EDR) API Pydantic

Test Coverage Package version Downloads License

This repository contains the edr-pydantic Python package. It provides Pydantic models for the OGC Environmental Data Retrieval (EDR) API. This can, for example, be used to help develop an EDR API using FastAPI.

Install

pip install edr-pydantic

Or to install from source:

pip install git+https://github.com/KNMI/edr-pydantic.git

Usage

from edr_pydantic.collections import Collection
from edr_pydantic.data_queries import EDRQuery, EDRQueryLink, DataQueries
from edr_pydantic.extent import Extent, Spatial
from edr_pydantic.link import Link
from edr_pydantic.observed_property import ObservedProperty
from edr_pydantic.parameter import Parameters, Parameter
from edr_pydantic.unit import Unit
from edr_pydantic.variables import Variables

c = Collection(
    id="hrly_obs",
    title="Hourly Site Specific observations",
    description="Observation data for UK observing sites",
    extent=Extent(
        spatial=Spatial(
            bbox=[
                [-15.0, 48.0, 5.0, 62.0]
            ],
            crs="WGS84"
        )
    ),
    links=[
        Link(
            href="https://example.org/uk-hourly-site-specific-observations",
            rel="service-doc"
        )
    ],
    data_queries=DataQueries(
        position=EDRQuery(
            link=EDRQueryLink(
                href="https://example.org/edr/collections/hrly_obs/position?coords={coords}",
                rel="data",
                variables=Variables(
                    query_type="position",
                    output_formats=[
                        "CoverageJSON"
                    ]
                )
            )
        )
    ),
    parameter_names=Parameters({
        "Wind Direction": Parameter(
            unit=Unit(
                label="degree true"
            ),
            observedProperty=ObservedProperty(
                id="https://codes.wmo.int/common/quantity-kind/_windDirection",
                label="Wind Direction"
            ),
            dataType="integer"
        )
    })
)

print(c.model_dump_json(indent=2, exclude_none=True, by_alias=True))

Will print

{
  "id": "hrly_obs",
  "title": "Hourly Site Specific observations",
  "description": "Observation data for UK observing sites",
  "links": [
    {
      "href": "https://example.org/uk-hourly-site-specific-observations",
      "rel": "service-doc"
    }
  ],
  "extent": {
    "spatial": {
      "bbox": [
        [
          -15.0,
          48.0,
          5.0,
          62.0
        ]
      ],
      "crs": "WGS84"
    }
  },
  "data_queries": {
    "position": {
      "link": {
        "href": "https://example.org/edr/collections/hrly_obs/position?coords={coords}",
        "rel": "data",
        "variables": {
          "query_type": "position",
          "output_formats": [
            "CoverageJSON"
          ]
        }
      }
    }
  },
  "parameter_names": {
    "Wind Direction": {
      "type": "Parameter",
      "data-type": "integer",
      "unit": {
        "label": "degree true"
      },
      "observedProperty": {
        "id": "https://codes.wmo.int/common/quantity-kind/_windDirection",
        "label": "Wind Direction"
      }
    }
  }
}

IMPORTANT: The arguments by_alias=True to model_dump_json() or model_dump() is required to get the output as shown above. Without by_alias=True the attribute data-type will be wrongly outputted as dataType. This is due an issue in the EDR spec and Pydantic.

Contributing

Make an editable install from within the repository root

pip install -e '.[test]'

Running tests

pytest tests/

Linting and typing

Linting and typing (mypy) is done using pre-commit hooks.

pip install pre-commit
pre-commit install
pre-commit run

Real world usage

This library is used to build an OGC Environmental Data Retrieval (EDR) API, serving automatic weather data station data from The Royal Netherlands Meteorological Institute (KNMI). See the KNMI Data Platform EDR API.

TODOs

Help is wanted in the following areas to fully implement the EDR spec:

  • See TODOs in code listing various small inconsistencies in the spec
  • In various places there could be more validation on content

License

Apache License, Version 2.0

Metadata

Release files for edr-pydantic 0.7.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 edr-pydantic 0.7.0
File Size Uploaded Provenance Actions
edr_pydantic-0.7.0.tar.gz 19.4 kB Without provenance Details for edr_pydantic-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for edr-pydantic 0.7.0
File Interpreter ABI Platform Actions
edr_pydantic-0.7.0-py3-none-any.whl Python 3 none any Details for edr_pydantic-0.7.0-py3-none-any.whl

Total release size: 32.2 kB

Release files / edr_pydantic-0.7.0.tar.gz

Download URL edr_pydantic-0.7.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
05a55927a6027b96ad0b8c30a7f983ce86535fca4653336e181179f4d113b71a
BLAKE2b-256 checksum
How to use checksums
71ff44f66126eb4b1ddb8cc2b781476b1a23e94c5394c85d931100cb2a4cdb93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / edr_pydantic-0.7.0-py3-none-any.whl

Download URL edr_pydantic-0.7.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3f50642cac76ea743eeca2c209b1214480448fe7b4f0b4668e5cfda7f50f704
BLAKE2b-256 checksum
How to use checksums
7076bcac4922d85e1101519889ecb666db2f7c808d3e737d4e4bb6091e9c9b54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Security for edr-pydantic 0.7.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