Skip to main content

geodantic

pypi versions

Lightweight, type-safe and spec-conforming GeoJSON parsing and validation using Pydantic.

Installation

pip install geodantic

Examples

Parse and validate GeoJSON features with custom properties:

import pydantic
from geodantic import Feature, Point

# Use your own properties Pydantic models
@pydantic.dataclasses.dataclass
class MyProperties:
    foo: str

data = {
    "type": "Feature",
    "geometry": {"type": "Point", "coordinates": [1, 2]},
    "properties": {"foo": "abc"},
}

# Parse and validate data into spec-conforming objects
parsed = Feature[Point, MyProperties](**data)
"""
Feature[Point, MyProperties](
    type=<GeoJSONObjectType.FEATURE: 'Feature'>, 
    bbox=None, 
    geometry=Point(
        type=<GeoJSONObjectType.POINT: 'Point'>, 
        bbox=None, 
        coordinates=(1.0, 2.0)
    ), 
    properties=MyProperties(foo='abc'), 
    id=None
)
"""

# Dump back into JSON using standard Pydantic methods
parsed.model_dump_json(exclude_unset=True, indent=2)
"""
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [
      1.0,
      2.0
    ]
  },
  "properties": {
    "foo": "abc"
  }
}
"""

Parse objects of arbitrary types:

from geodantic import GeometryCollection

data = {
    "type": "GeometryCollection",
    "geometries": [
        {
            "type": "Polygon",
            "coordinates": [[[1, 2], [3, 4], [5, 6], [1, 2]]],
            "bbox": [1, 2, 3, 4],
        },
        {
            "type": "GeometryCollection",
            "geometries": [{"type": "Point", "coordinates": [1, 2]}],
        },
    ],
}

# Parse any geometry type
parsed = GeometryCollection(**data)
"""
GeometryCollection(
    type=<GeoJSONObjectType.GEOMETRY_COLLECTION: 'GeometryCollection'>, 
    bbox=None, 
    geometries=[
        Polygon(
            type=<GeoJSONObjectType.POLYGON: 'Polygon'>, 
            bbox=(1.0, 2.0, 3.0, 4.0), 
            coordinates=[[(1.0, 2.0), (3.0, 4.0), (5.0, 6.0), (1.0, 2.0)]]
        ), 
        GeometryCollection(
            type=<GeoJSONObjectType.GEOMETRY_COLLECTION: 'GeometryCollection'>, 
            bbox=None, 
            geometries=[
                Point(
                    type=<GeoJSONObjectType.POINT: 'Point'>, 
                    bbox=None, 
                    coordinates=(1.0, 2.0)
                )
            ]
        )
    ]
)
"""

Contributing

Set up the project using Poetry:

poetry install

Format the code:

make lint

Run tests:

make test

Check for typing and format issues:

make check

Metadata

Release files for geodantic 0.4.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 geodantic 0.4.0
File Size Uploaded Provenance Actions
geodantic-0.4.0.tar.gz 4.9 kB Without provenance Details for geodantic-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 10.8 kB

Release files / geodantic-0.4.0.tar.gz

Download URL geodantic-0.4.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ef53322467f610317994493a58b31ffa48336ff99b2ad1b20474e20c01d9d669
BLAKE2b-256 checksum
How to use checksums
1625a0942657dc817dc2ba91dd3c1f90a6a7f735a3a8dae026ea7ecde06fb5c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.12.1 Linux/6.2.0-1018-azure

Release files / geodantic-0.4.0-py3-none-any.whl

Download URL geodantic-0.4.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fffc3f1430bbdb9c516a4df7cc03c30021e95d03e891b5ecf3308bade864f97
BLAKE2b-256 checksum
How to use checksums
78619fcb2c9c05320145d57ba8e287ae59009a33b7044518e42ea90a3cb9eef8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.12.1 Linux/6.2.0-1018-azure

Security for geodantic 0.4.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