PySTAC Client
PySTAC Client is a Python package for searching SpatioTemporal Asset Catalog (STAC) APIs. It builds upon the PySTAC library by offering higher-level functionality and the ability to leverage STAC API search endpoints seamlessly. The current version is 0.9.0, with ongoing active development and regular releases.
Warnings
- deprecated The `get_all_items()` method on `ItemSearch` is deprecated. Users should migrate to `item_collection()` for retrieving all items as a single `ItemCollection` object.
- breaking The `STAC_URL` environment variable is no longer supported for automatically configuring the `Client.open()` method or the CLI. The STAC API URL must now be explicitly provided as an argument.
- gotcha When using `Client.collection_search()`, if the connected STAC API does not explicitly support the Collection Search Extension, `pystac-client` may perform client-side filtering. This can be inefficient for large catalogs and might not return comprehensive results from the server perspective.
- gotcha Iterating through `search.items()` or `search.collections()` without setting `max_items` can lead to fetching and iterating over an entire large STAC catalog, potentially consuming significant memory and network resources.
- gotcha The simplified query syntax (`query={property: value}`) often sends property values as strings (except for `gsd`). If the STAC API expects numeric or other data types for specific properties, this can lead to incorrect or no matches.
- gotcha Custom 'modifier' functions passed to `Client.open()` are expected to modify STAC objects in-place and return `None`. Returning a modified copy or a non-None value that isn't the original object can lead to unexpected behavior or warnings.
Install
-
pip install pystac-client
Imports
- Client
from pystac_client import Client
Quickstart
import os
from pystac_client import Client
# Replace with a real STAC API URL or set via environment variable for testing
STAC_API_URL = os.environ.get('STAC_API_URL', 'https://earth-search.aws.element84.com/v1')
# 1. Create a client instance
client = Client.open(STAC_API_URL)
print(f"Connected to STAC API: {STAC_API_URL}")
# 2. Perform an item search
search = client.search(
max_items=10,
collections=['sentinel-2-l2a'],
bbox=[-72.5, 40.5, -72, 41]
)
# 3. Get matched items and print IDs
matched_items_count = search.matched()
print(f"Found {matched_items_count} items.")
print("First 10 item IDs:")
for item in search.items():
print(item.id)
# 4. Convert all items to an ItemCollection (use with caution for large results)
# item_collection = search.item_collection()
# print(f"ItemCollection contains {len(item_collection.items)} items.")