Skip to main content

xpystac

xpystac provides the glue that allows xarray.open_dataset and xarray.open_datatree to accept pystac assets.

The goal is that as long as this library is in your env, you should never need to think about it. It will read data for an asset pointing to a COG, a zarr store, a virtual icechunk store, or a kerchunk reference file.

This library does not try to replace the need for the stacking and mosaicing that odc-stac and stackstac provide. When loading a pystac item where each asset contains a COG representing a particular band you are better off using those libraries directly.

Install

pip install xpystac

Examples

Read from a COG

import pystac
import xarray as xr

item = pystac.Item.from_file(
    "https://raw.githubusercontent.com/stac-utils/pystac/v1.12.2/tests/data-files/examples/1.0.0/simple-item.json"
)
asset = item.assets["visual"]

xr.open_dataset(asset)

Read from a virtual Icechunk store

import pystac
import xarray as xr

collection = pystac.Collection.from_file(
    "https://raw.githubusercontent.com/stac-utils/xpystac/refs/heads/main/tests/data/virtual-icechunk-collection.json"
)

# Get the latest version of the collection-level asset
assets = collection.get_assets(role="latest-version")
asset = next(iter(assets.values()))

xr.open_dataset(asset)

Icechunk assets on S3-compatible object stores that aren't AWS (e.g. MinIO, other self-hosted S3 gateways) are also supported, via a storage:schemes entry of type custom-s3:

"storage:schemes": {
  "my-minio": {
    "type": "custom-s3",
    "platform": "https://minio.example.com",
    "bucket": "my-bucket"
  }
}

Here are a few examples from the Planetary Computer Docs which has some good examples of collection-level assets used to catalog zarr stores and kerchunk reference files.

import planetary_computer
import pystac_client
import xarray as xr


catalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1",
    modifier=planetary_computer.sign_inplace,
)

Read from a kerchunk reference file (ref):

collection = catalog.get_collection("nasa-nex-gddp-cmip6")
asset = collection.assets["ACCESS-CM2.historical"]

xr.open_dataset(asset, patch_url=planetary_computer.sign)

Read from a zarr file (ref)

collection = catalog.get_collection("daymet-daily-hi")
asset = collection.assets["zarr-abfs"]

xr.open_dataset(asset, patch_url=planetary_computer.sign)

Note that this zarr asset uses the xarray-assets extension to store open_kwargs and storage_options which xpystac can then pass along to xr.open_dataset.

Open as a datatree

import xarray as xr
import pystac_client


client = pystac_client.Client.open("https://stac-api.grid4earth.eu")
items = client.search(collections=["sentinel-2-l2a"]).item_collection()
item = items.items[0]
asset = item.assets["product"]

tree = xr.open_datatree(asset, engine="stac")

How it works

When you call xarray.open_dataset(object, engine="stac") this library maps that open call to the correct library. Depending on the type of object that might be back to xarray.open_dataset itself but with the engine and other options pulled from the pystac object.

Prior Art

This work is inspired by https://github.com/TomAugspurger/staccontainers and the discussion in https://github.com/stac-utils/pystac/issues/846

Metadata

Release files for xpystac 0.6.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 xpystac 0.6.0
File Size Uploaded Provenance Actions
xpystac-0.6.0.tar.gz 236.7 kB With provenance Details for xpystac-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 248.9 kB

Release files / xpystac-0.6.0.tar.gz

Download URL xpystac-0.6.0.tar.gz
Size 236.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8001333dc1d7e1d8556b5418e6902d675aa4bc9bcf646474833829173298a4cb
BLAKE2b-256 checksum
How to use checksums
8e6a5c756078dc048e4489d574ec73b0df0c9b227e105908f8b6c47df54af821
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / xpystac-0.6.0-py3-none-any.whl

Download URL xpystac-0.6.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
273dc1e98ba6399c86c88dd7adec8bb7a52589e0e3e4d37ded38025b3ad56443
BLAKE2b-256 checksum
How to use checksums
4209167339ac9cb310f0de37e5435c1b2d920706609da845212400b645382320
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for xpystac 0.6.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for xpystac-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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