PySTAC
PySTAC is a Python library for working with the SpatioTemporal Asset Catalog (STAC) specification. It provides tools for reading, creating, and modifying STAC Catalogs, Collections, and Items. Currently at version 1.14.3, the library maintains a regular release cadence with updates addressing bug fixes and new features, including support for the latest STAC specification versions.
Warnings
- breaking PySTAC v1.12.0 changed the default STAC specification version to 1.1.0. This means new catalogs created or existing catalogs processed by PySTAC will default to 1.1.0. Users working with older STAC versions should be aware of potential migration needs or explicitly set the STAC version.
- breaking As of Spring 2026, STAC extension implementations (e.g., Electro-Optical, Projection) have moved from being part of the core `pystac` package to their own independent Python packages (e.g., `pystac-ext-projection`). This is a breaking change for how extensions are accessed and versioned.
- gotcha Manually setting `pystac.set_stac_version()` or the `PYSTAC_STAC_VERSION_OVERRIDE` environment variable only alters the `stac_version` property written to JSON. It does not change the internal object structure or enforce validation against that specific version, potentially leading to invalid STAC.
- gotcha Validation functionality in PySTAC requires the optional `jsonschema` dependency. If you attempt to call `.validate()` methods without installing `pystac[validation]`, it will result in an error or unexpected behavior.
- gotcha Asset HREFs (paths to data) can be absolute or relative. Relative HREFs are resolved based on the Item's metadata file location. Incorrect handling of relative paths can lead to broken links in generated STAC catalogs.
Install
-
pip install pystac -
pip install 'pystac[validation]' -
pip install 'pystac[orjson]'
Imports
- Catalog
from pystac import Catalog
- Collection
from pystac import Collection
- Item
from pystac import Item
- Asset
from pystac import Asset
- Link
from pystac import Link
- STACVersion
from pystac.version import STACVersion
- EOExtension
from pystac.extensions.eo import EOExtension
Quickstart
import pystac
from datetime import datetime, timezone
from shapely.geometry import Polygon, mapping
from tempfile import TemporaryDirectory
import os
# 1. Create a temporary directory for the STAC catalog
tmp_dir = TemporaryDirectory()
catalog_dir = os.path.join(tmp_dir.name, 'my_stac_catalog')
# 2. Create a root Catalog
catalog = pystac.Catalog(
id='example-catalog',
description='A simple example STAC Catalog for demonstration.'
)
# 3. Create an Item
# Define spatial and temporal extents for the item
bbox = [-10.0, -10.0, 10.0, 10.0]
geometry = mapping(Polygon.from_bounds(*bbox))
# Create a datetime object for the item
dt = datetime(2023, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
# Create a STAC Item
item = pystac.Item(
id='example-item-1',
geometry=geometry,
bbox=bbox,
datetime=dt,
properties={}
)
# Add an asset to the item
asset_href = 'https://example.com/data/image.tif'
item.add_asset(
key='image',
asset=pystac.Asset(
href=asset_href,
media_type=pystac.MediaType.GEOTIFF,
roles=['data']
)
)
# 4. Add the item to the catalog
catalog.add_item(item)
# 5. Normalize HREFs and save the catalog
catalog.normalize_hrefs(catalog_dir)
catalog.save(catalog_type=pystac.CatalogType.SELF_CONTAINED)
print(f"STAC Catalog saved to: {catalog_dir}")
# Clean up the temporary directory (optional)
# tmp_dir.cleanup()