Skip to content
Snippets Groups Projects
user avatar
Rémi authored
1a74bc41
History

Description

This is an example how to use pydantic-pystac-extensions.

Installation

Python package is hosted in gitlab package registry. You need to show pip the extra indexes:

pip install pydantic-pystac-extensions-example \
  --index-url https://forgemia.inra.fr/api/v4/projects/14448/packages/pypi/simple \
  --index-url https://forgemia.inra.fr/api/v4/projects/14431/packages/pypi/simple

Where 14431 and 14448 are the project ID respectively for pydantic-pystac-extensions and pydantic-pystac-extensions-example.

Usage

Apply extension to a STAC object

from pydantic_pystac_extensions_example import MyExtension

stac_item_or_asset = ...
ext = MyExtension.ext(stac_item_or_asset, add_if_missing=True)
ext.apply(
    name="test",
    authors=["michel", "denis"],
    version="alpha",
)

Read extension metadata from a STAC object

from pydantic_pystac_extensions_example import MyExtension

stac_item_or_asset = ...
ext = MyExtension(stac_item_or_asset)
print(ext.name)
print(ext.version)
print(ext.authors)

Developer's checklist

  1. Implement your own custom extension (take a look in my_extension.py), which basically means:
  • create a pydantic.BaseModel for your extension metadata model (your model can inherit from pydantic_pystac_extensions.ExtensionBaseModel)
  • use the pydantic_pystac_extensions.create_extension_cls to create the extension class from your model
  • use the future URL for the JSON schema that you will be using later (see point 4, use raw content URL)
  1. Push the code on gitlab and copy the schema generated at the 1st CI job, or generate the json schema using MyExtension.export_schema()
  2. Put the json schema in a git repository (we recommend to use https://forgemia.inra.fr/umr-tetis/stac/extensions/schemas.git)
  3. Push and tag to publish the pip package

As explained in the installation section, you will need to note the pip index of gitlab.

Important notice

  • CI template: use the provided CI template in .gitlab-ci.yml
  • use the pydantic_pystac_extensions.testing module to perform common tests !