Skip to main content

CoverageJSON Pydantic

Test Coverage Package version Downloads License

This repository contains the coveragejson-pydantic Python package. It provides Pydantic models for CoverageJSON. This can, for example, be used to develop an API using FastAPI serving or receiving CoverageJSON.

Install

pip install covjson-pydantic

Or you can install directly from source:

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

Usage

from datetime import datetime, timezone
from pydantic import AwareDatetime
from covjson_pydantic.coverage import Coverage
from covjson_pydantic.domain import Domain, Axes, ValuesAxis, DomainType
from covjson_pydantic.ndarray import NdArrayFloat

c = Coverage(
    domain=Domain(
        domainType=DomainType.point_series,
        axes=Axes(
            x=ValuesAxis[float](values=[1.23]),
            y=ValuesAxis[float](values=[4.56]),
            t=ValuesAxis[AwareDatetime](values=[datetime(2024, 8, 1, tzinfo=timezone.utc)]),
        ),
    ),
    ranges={
        "temperature": NdArrayFloat(axisNames=["x", "y", "t"], shape=[1, 1, 1], values=[42.0])
    }
)

print(c.model_dump_json(exclude_none=True, indent=4))

Will print

{
    "type": "Coverage",
    "domain": {
        "type": "Domain",
        "domainType": "PointSeries",
        "axes": {
            "x": {
                "values": [
                    1.23
                ]
            },
            "y": {
                "values": [
                    4.56
                ]
            },
            "t": {
                "values": [
                    "2024-08-01T00:00:00Z"
                ]
            }
        }
    },
    "ranges": {
        "temperature": {
            "type": "NdArray",
            "dataType": "float",
            "axisNames": [
                "x",
                "y",
                "t"
            ],
            "shape": [
                1,
                1,
                1
            ],
            "values": [
                42.0
            ]
        }
    }
}

Contributing

Make an editable installation 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
  • edr-pydantic - Pydantic data models for the Environmental Data Retrieval (EDR) API
  • geojson-pydantic - Pydantic data models for the GeoJSON spec

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 CovJSON spec:

  • The MultiPolygon and MultiPolygonSeries domain types are not supported.
  • The Section domain type is not supported.
  • Not all requirements in the spec relating different fields are implemented.

License

Apache License, Version 2.0

Metadata

Release files for covjson-pydantic 0.8.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 covjson-pydantic 0.8.0
File Size Uploaded Provenance Actions
covjson_pydantic-0.8.0.tar.gz 22.1 kB Without provenance Details for covjson_pydantic-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for covjson-pydantic 0.8.0
File Interpreter ABI Platform Actions
covjson_pydantic-0.8.0-py3-none-any.whl Python 3 none any Details for covjson_pydantic-0.8.0-py3-none-any.whl

Total release size: 36.3 kB

Release files / covjson_pydantic-0.8.0.tar.gz

Download URL covjson_pydantic-0.8.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
66fb12da6634b22ff3c401b3b1e3e42a1abe8dc7830283a0655ca3ec9fc9ade0
BLAKE2b-256 checksum
How to use checksums
4b2b130ad9c7b5318974c1aa5da0d73c3c948f695002793253b99ffc896f2dc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Release files / covjson_pydantic-0.8.0-py3-none-any.whl

Download URL covjson_pydantic-0.8.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c38ce951d2991403a252a28919eb2912cb0c34bf76ddca2fb8d4d1aac31a27bc
BLAKE2b-256 checksum
How to use checksums
db91318355d3a76ee3d52cddf1e4e3c63eb942e80fe917d853722cdeecb09832
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.34.2

Security for covjson-pydantic 0.8.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