Skip to main content

stac-pydantic-extensions

CI PyPI version Python versions License

Pydantic data models for STAC extensions, built on top of stac-pydantic.

stac-pydantic-extensions lets you attach, read, modify, and migrate STAC extension fields (eo, raster, proj, view, sat, sci, rd, ssys, wmts, ...) on Items, Collections, Assets and Bands, with validation and version migration handled for you.

Features

  • Typed access to extension fields — item.ext.eo.cloud_cover, item.ext.raster.spatial_resolution, etc.
  • Add / remove extensions on the fly, recursively across assets and bands.
  • Version migration — upgrade Items written against older extension schemas (e.g. eo/v1.0.0, raster/v1.1.0) to the current ones, including the eo:bands / raster:bands → bands merge introduced in the v2.0.0 extensions.
  • Multiple extensions at once, without them clobbering each other's fields.
  • Works with plain STAC Items that don't declare any extensions yet.

Installation

pip install stac-pydantic-extensions

or, with uv:

uv add stac-pydantic-extensions

Requires Python 3.13+.

Quickstart

import json

from stac_pydantic_extensions import ExtendedItem, Item

with open("item-sentinel2.json") as f:
    raw_item = json.load(f)

item = Item.model_validate(raw_item)
extended_item = ExtendedItem(stac_object=item)

# Read extension fields declared on the item
print(extended_item.ext.eo.cloud_cover)          # 21.22
print(extended_item.show_ext_names())            # {'eo', 'view', 'proj', 'raster'}

# Extensions declared on assets/bands are available the same way
red_band = extended_item.stac_object.assets["B04"]
extended_band = ExtendedItem(stac_object=red_band)
print(extended_band.ext.eo.common_name)           # "red"
print(extended_band.ext.raster.spatial_resolution)  # 10

# Add a new extension to an item that doesn't have it yet
extended_item.add_extension("raster")
extended_item.ext.raster.spatial_resolution = 10

# Serialize back out
updated = extended_item.model_dump()

Migrating older extension versions

from stac_pydantic_extensions import ExtendedItem, Item

old_item = Item.model_validate(raw_item_with_v1_extensions)

migrated = ExtendedItem(stac_object=old_item).migrate()
# stac_extensions now point at the latest schema versions, and any
# eo:bands / raster:bands entries have been merged into `bands`.

Supported extensions

Extension Prefix
Electro-Optical eo
Projection proj
Raster raster
View Geometry view
Satellite sat
Scientific Citation sci
Remote Data rd
Solar System ssys
Web Map Tile Service wmts

Development

This project uses uv for dependency management.

git clone https://github.com/s-boomi/stac-pydantic-extensions.git
cd stac-pydantic-extensions
uv sync --group dev

Run the test suite:

uv run pytest --cov stac_pydantic_extensions --cov-report term-missing

Run linting, formatting and type checks:

uv run pre-commit run --all-files
uv run ty check
SKIP=ty uv run pre-commit run --all-files

Releasing

Releases are published to PyPI via PyPI trusted publishing from the .github/workflows/release.yml workflow. To cut a release:

  1. Bump version in pyproject.toml.
  2. Tag the commit with the matching version (e.g. v0.2.0) and push the tag, or create a GitHub Release — this triggers the release job.
  3. The workflow verifies the tag matches the package version, builds the sdist/wheel with uv build, and publishes with uv publish.

License

Distributed under the MIT License. See LICENSE for details.

Metadata

Release files for stac-pydantic-extensions 0.2.2

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

Source distribution (sdist)

Source distribution for stac-pydantic-extensions 0.2.2
File Size Uploaded
stac_pydantic_extensions-0.2.2.tar.gz 24.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stac-pydantic-extensions 0.2.2
File Interpreter ABI Platform
stac_pydantic_extensions-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 67.5 kB

Release files / stac_pydantic_extensions-0.2.2.tar.gz

Download URL stac_pydantic_extensions-0.2.2.tar.gz
Size 24.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b4fff8bc6f8fbfe85d28539be5079b31e6ab6677c9034f72e294be5eb987127f
BLAKE2b-256 checksum
How to use checksums
e2f612b9c8e0073cb1420777aef414e38700f2a75e2555c1e2c5514c5557ff16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / stac_pydantic_extensions-0.2.2-py3-none-any.whl

Download URL stac_pydantic_extensions-0.2.2-py3-none-any.whl
Size 42.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a3cb2b3803b8bb6e0040436be1ec09b5cba76b421480958679ea0aca8c5d7b9
BLAKE2b-256 checksum
How to use checksums
5af5d7d163c55227816143877e4231778c42d809bd8dbc8d26af018a9f65ec59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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