Skip to main content

STAC API

Install terrapi client library

The library terrapi-client offers functions to easily work with the private STAC API. It builds on top of the Python library terrapi for authentication with the terrabyte authentication service.

pip install git+https://github.com/DLR-terrabyte/terrapi-client.git@latest-release

How to use your private STAC API

Create new private/shared STAC Collection

import pystac
from terrapi.client import open_private_catalog, create_private_collection

# Connect to the terrabyte private STAC API
catalog = open_private_catalog()

# All private collections are prefixed with your terrabyte/LRZ username
# All shared collections are prefixed with the DSS container id (e.g., pn56su-dss-0001)
prefix = '<your username>'

collection = pystac.Collection(
f"{prefix}.testcollection",
"description",
pystac.Extent(
pystac.SpatialExtent([[-180, -90.180, 90]]),
pystac.TemporalExtent([[None, None]]),
),
)
create_private_collection(catalog, collection)

Create new STAC item in private/shared STAC collection

from terrapi.client import open_private_catalog, create_private_item
from datetime import datetime

geom = {"type": "Point", "coordinates": [0, 0]}
item = pystac.Item("test_item", geom, None, datetime=datetime.now(), properties={})

catalog = open_private_catalog()
create_private_item(catalog, item, '<your-stac-collection-id>')

Explore the STAC catalog

from terrapi import open_private_catalog

# Connect to the terrabyte private STAC API
catalog = open_private_catalog()

# list the IDs of all STAC catalog collections
for collection in catalog.get_all_collections():
print(collection.id)

# Now query a STAC collection
start = datetime.now().replace(hour=0, minute=0, second=0)
end = datetime.now().replace(hour=23, minute=59, second=59)

query = {

}

results = catalog.search(
collections=[f"{prefix}.testcollection"],
datetime=[start, end],
query=query,
)
items = results.item_collection_as_dict()
print("%s items found" % len(items['features']))

Delete STAC item

from terrapi.client import open_private_catalog, delete_private_item
catalog = open_private_catalog()
delete_private_item(catalog, '<your-stac-item-id>', '<your-stac-collection-id>')

Delete STAC collection

from terrapi.client import open_private_catalog, delete_private_collection
catalog = open_private_catalog()
delete_private_collection(catalog, '<your-stac-collection-id>')