PySTAC Client

0.9.0 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a STAC API, perform a basic item search using geographic bounding box and collection filters, and iterate through the results. It includes a placeholder for a STAC API URL, which can be overridden by an environment variable for easier testing.

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.")

view raw JSON →