Create an Item with themes

Install the package, then run this complete example. The vocabulary and concept URIs are illustrative.

import json
from datetime import datetime, timezone

import pystac
from pystac.extensions.themes import Theme, ThemeConcept, ThemesExtension

item = pystac.Item(
    id="example-climate-resource",
    geometry=None,
    bbox=None,
    datetime=datetime(2026, 1, 1, tzinfo=timezone.utc),
    properties={},
)
theme = Theme(
    scheme="https://example.com/themes",
    concepts=[
        ThemeConcept(
            id="climate",
            title="Climate",
            description="Climate-related resources",
            url="https://example.com/concepts/climate",
        )
    ],
)
extension = ThemesExtension.ext(item, add_if_missing=True)
extension.apply([theme])

serialized = item.to_dict()
assert ThemesExtension.get_schema_uri() in serialized["stac_extensions"]
assert serialized["properties"]["themes"] == [theme.to_dict()]

restored_item = pystac.Item.from_dict(json.loads(json.dumps(serialized)))
restored_themes = ThemesExtension.ext(restored_item).themes
assert restored_themes is not None
assert restored_themes[0].concepts[0].id == "climate"

add_if_missing=True adds the schema URI to stac_extensions. apply() replaces the theme list in Item properties. Use ThemesExtension.ext() again to access an existing object's themes.

Serialization preserves metadata without validating it. Continue with updates, Collection summaries, and validation.