Skip to main content

STAC API

Install terrabyte client library

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

pip install git+https://github.com/DLR-terrabyte/terrabyte-client.git

How to use your private STAC API

Create new private/shared STAC Collection

import pystac
from terrabyte_client.client import create_private_collection

# 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 terrabyte_client.client import create_private_item
from datetime import datetime

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

Explore the STAC catalog

from terrabyte_client 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 terrabyte_client.client import delete_private_item
delete_private_item(catalog, item.id, collection.id)

Delete STAC collection

from terrabyte_client.client import delete_private_collection
delete_private_collection(catalog, collection.id)