Data management in SDK

Use data management functionalities of the SDK using PySTAC.


Overview

Manage geospatial data in your storage with PySTAC.

View repository

PySTAC authentication

After you’ve authenticated with the SDK, create a PySTAC client connection.

Python
UP42_client = up42.stac_client()

The code samples on this page require an initialized UP42_client object.

Class: Collection

A PySTAC class that represents a STAC collection. See the PySTAC documentation for more information.

A STAC collection is a delivery you receive after a completed order or a finished processing job.

Attributes

AttributeDescription
id

str

The STAC collection ID.

title

Optional[str]

The title of the STAC collection.

assets

dict[str, Asset]

A dictionary where keys are asset names and values are Asset objects linked to this STAC collection.

A collection might optionally contain one asset: “Original Delivery”. If this asset isn’t present at the collection level, it’s stored in the individual STAC items instead.

stac_extensions

list[str]

Enabled STAC extensions.


Properties

up42

Provides access to all UP42-specific metadata embedded within the collection.

Python
import json
# Select a STAC collection
stac_collection_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC collection info
collection = UP42_client.get_collection(stac_collection_id)
up42_properties = collection.up42
# Define output
readable_json = json.dumps(up42_properties._reference, indent=2)
print(readable_json)

Methods

get_collections

Retrieves all STAC collections. Returns Iterator[Collection]. Use itertools.islice to offset and limit the results. See the PySTAC documentation for more information.

Python
from itertools import islice
# Search for STAC collections
collections = UP42_client.get_collections()
# Define output
for collection in islice(collections, 0, 5): # Print first 5 results
print(f"- STAC collection ID: {collection.id}")
print(f" Filename: {collection.title}")
print(f" User title: {collection.up42.title}")
print(f" Source: {collection.up42.source}")
for asset_key, asset_obj in collection.assets.items(): # Print the only asset if it exists
print(f" Asset key: {asset_key}")
print(f" Asset title: {asset_obj.title}")
print(f" Media type: {asset_obj.media_type}")
print(f" Roles: {', '.join(asset_obj.roles)}")
print(f" Link: {asset_obj.href}")
print()

get_collection

Retrieves a specific STAC collection associated with an item. Returns Collection. See the PySTAC documentation for more information.

Python
# Select a STAC item
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch the parent STAC collection
collection = UP42_client.get_item(stac_item_id).get_collection()
# Define output
print(f"STAC collection ID: {collection.id}")
print(f"Filename: {collection.title}")
print(f"User title: {collection.up42.title}")
print(f"Source: {collection.up42.source}")
for asset_key, asset_obj in collection.assets.items(): # Print the only asset if it exists
print(f"Asset key: {asset_key}")
print(f"Asset title: {asset_obj.title}")
print(f"Media type: {asset_obj.media_type}")
print(f"Roles: {', '.join(asset_obj.roles)}")
print(f"Link: {asset_obj.href}")

Class: Item

A PySTAC class that represents a STAC item. See the PySTAC documentation for more information.

A STAC item is an individual scene that represents inseparable data and metadata. A STAC item has a unique spatiotemporal extent, that is, has one AOI and acquisition time in its characteristics.

Attributes

AttributeDescription
id

str

The STAC item ID.

geometry

Optional[Union[geojson.Polygon, geojson.MultiPolygon]]

The STAC item geometry in the GeoJSON format.

bbox

Optional[BoundingBox]

The bounding box that encloses the STAC item geometry.

datetime

Optional[str]

The date and time when the sensor acquired the data.

properties

dict

Additional STAC item metadata.

assets

dict[str, Asset]

A dictionary where keys are asset names and values are Asset objects linked to this STAC item.

stac_extensions

list[str]

Enabled STAC extensions.


Properties

up42

Provides access to all UP42-specific metadata embedded within the item.

Python
import json
# Select a STAC item
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item info
item = UP42_client.get_item(stac_item_id)
up42_properties = item.up42
# Define output
readable_json = json.dumps(up42_properties._reference, indent=2)
print(readable_json)

Methods

Retrieves STAC items matching search criteria. Returns ItemSearch. Use itertools.islice to offset and limit the results. See the PySTAC documentation for more information.

ParameterDescription
filter

Optional[SearchFilter]

The CQL2 search filter.

ids

Optional[List[str]]

The IDs of STAC items you want to include in search results.

bbox

Optional[BoundingBox]

A search geometry in the GeoJSON format. Returns images that intersect with the defined rectangle and may not fully cover it. Use only if intersects isn’t specified.

intersects

Optional[geojson.Polygon]

A polygon in the GeoJSON format.

datetime

Optional[str]

The date and time when the sensor acquired the data.

Python
from itertools import islice
# Define the search filter
filter = {
"op": "=",
"args": [
{"property": "order_id"}, # This example searches by order ID
"68567134-27ad-7bd7-4b65-d61adb11fc78", # The selected order ID
],
}
# Search for STAC items
items = UP42_client.search(filter=filter)
# Define output
15 collapsed lines
for item in islice(items.items(), 0, 5): # Print first 5 results
print(f"- STAC item ID: {item.id}")
print(f" User title: {item.up42.title}")
print(f" User tags: {item.up42.tags}")
print(f" Source: {item.up42.source}")
print(f" Job ID: {item.up42.job_id or 'N/A'}") # For jobs
print(f" Order ID: {item.up42.order_id or 'N/A'}") # For orders
print(f" Properties: {item.properties}")
for asset_key, asset_obj in islice(item.assets.items(), 0, 3): # Print first 3 assets in each item
print(f" - Asset key: {asset_key}")
print(f" Asset title: {asset_obj.title}")
print(f" Media type: {asset_obj.media_type}")
print(f" Roles: {', '.join(asset_obj.roles)}")
print(f" Link: {asset_obj.href}")
print()

get_items

Retrieves all STAC items. Returns Iterator[Item]. Use itertools.islice to offset and limit the results. See the PySTAC documentation for more information.

Python
from itertools import islice
# Search for STAC items
items = UP42_client.get_items()
# Define output
15 collapsed lines
for item in islice(items, 0, 5): # Print first 5 results
print(f"- STAC item ID: {item.id}")
print(f" User title: {item.up42.title}")
print(f" User tags: {item.up42.tags}")
print(f" Source: {item.up42.source}")
print(f" Job ID: {item.up42.job_id or 'N/A'}") # For jobs
print(f" Order ID: {item.up42.order_id or 'N/A'}") # For orders
print(f" Properties: {item.properties}")
for asset_key, asset_obj in islice(item.assets.items(), 0, 3): # Print first 3 assets in each item
print(f" - Asset key: {asset_key}")
print(f" Asset title: {asset_obj.title}")
print(f" Media type: {asset_obj.media_type}")
print(f" Roles: {', '.join(asset_obj.roles)}")
print(f" Link: {asset_obj.href}")
print()

get_item

Retrieves a specific STAC item by its ID. Returns Item. See the PySTAC documentation for more information.

ParameterDescription
id

str

The STAC item ID.

Python
from itertools import islice
# Select a STAC item
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item info
item = UP42_client.get_item(stac_item_id)
# Define output
13 collapsed lines
print(f"STAC item ID: {item.id}")
print(f"User title: {item.up42.title}")
print(f"User tags: {item.up42.tags}")
print(f"Source: {item.up42.source}")
print(f"Job ID: {item.up42.job_id or 'N/A'}") # For jobs
print(f"Order ID: {item.up42.order_id or 'N/A'}") # For orders
print(f"Properties: {item.properties}")
for asset_key, asset_obj in islice(item.assets.items(), 0, 3): # Print first 3 assets
print(f" - Asset key: {asset_key}")
print(f" Asset title: {asset_obj.title}")
print(f" Media type: {asset_obj.media_type}")
print(f" Roles: {', '.join(asset_obj.roles)}")
print(f" Link: {asset_obj.href}")

update

Changes the title and tags of a STAC item.

Python
# Select a STAC item
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item info
item = UP42_client.get_item(stac_item_id)
# Update the title in our database
item.up42.title = "Pleiades Berlin"
item.update()
# Define output to check the changes
print(f"STAC item ID: {item.id}")
print(f"User title: {item.up42.title}")
Python
# Select a STAC item
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item info
item = UP42_client.get_item(stac_item_id)
# Define new tags to add
new_tags = ["ortho-done"]
# Update tags in our database
item.up42.tags = item.up42.tags + new_tags # This adds new tags to existing ones
# item.up42.tags = ["only-ortho-done"] # Uncomment to overwrite existing tags
item.update()
# Define output to check the changes
print(f"STAC item ID: {item.id}")
print(f"User tags: {item.up42.tags}")

Class: Asset

A PySTAC class that represents a STAC asset. See the PySTAC documentation for more information.

A STAC asset is a geospatial feature of a STAC item. For example, a band in an optical image, a thumbnail, or a metadata file.

Attributes

AttributeDescription
href

str

The URL of a downloadable or a streamable file related to the STAC asset.

title

Optional[str]

The STAC asset title.

description

Optional[str]

The STAC asset description.

media_type

Optional[str]

The STAC asset data type.

roles

Optional[list[str]]

The purpose of the STAC asset.


Properties

file.url

Retrieves the signed URL for the asset file. Returns str. Uses the file helper object.

Python
# Select a STAC item
4 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item info
item = UP42_client.get_item(stac_item_id)
# Find the first asset with the 'multispectral' role
multispectral_asset = next(
(asset for asset in item.assets.values() if asset.roles and "multispectral" in asset.roles),
None,
)
# Define output
if multispectral_asset:
print(f"The signed URL: {multispectral_asset.file.url}")
else:
print("No asset found.")

Methods

file.download

Downloads assets from storage. Uses the file helper object.

ParameterDescription
output_directory

Union[str, pathlib.Path]

The file output directory.


Original deliveries


Python
import pathlib
# Select a STAC item
5 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Define a directory to store the downloaded ZIP
output_dir = pathlib.Path.home() / "Desktop" / "original_zipped_deliveries"
output_dir.mkdir(parents=True, exist_ok=True)
# Fetch the parent STAC collection
collection = UP42_client.get_item(stac_item_id).get_collection()
# Find the asset with the 'original' role
original_delivery = next(
(asset for asset in collection.assets.values() if asset.roles and "original" in asset.roles),
None,
)
# Download the file
if original_delivery:
downloaded_file_path = original_delivery.file.download(output_directory=output_dir)
print(f"\nThe original delivery downloaded to '{downloaded_file_path}'.")
else:
print(f"The original delivery wasn't found.")
Python
import pathlib
# Define the search filter
14 collapsed lines
filter = {
"op": "=",
"args": [
{"property": "order_id"}, # This example searches by order ID
"68567134-27ad-7bd7-4b65-d61adb11fc78", # The selected order ID
],
}
# Search for STAC items
items = UP42_client.search(filter=filter)
# Define a directory to store the downloaded files
output_dir = pathlib.Path.home() / "Desktop" / "original_zipped_deliveries"
output_dir.mkdir(parents=True, exist_ok=True)
# Fetch the parent STAC collections
for item in items.items():
collection = item.get_collection()
if not collection:
continue
# Find the assets with the 'original' role
original_delivery = next(
(asset for asset in collection.assets.values() if asset.roles and "original" in asset.roles),
None,
)
# Download the file
if original_delivery:
downloaded_file_path = original_delivery.file.download(output_directory=output_dir)
print(f"\nThe original delivery was downloaded to '{downloaded_file_path}'.")
break
else:
print(f"The original delivery wasn't found.")
Python
import pathlib
# Define the search criteria
8 collapsed lines
orders = up42.Order.all(
status=["FULFILLED"],
tags=["project-7"],
)
# Define a directory to store the downloaded files
output_dir = pathlib.Path.home() / "Desktop" / "original_zipped_deliveries"
output_dir.mkdir(parents=True, exist_ok=True)
# Process each order
21 collapsed lines
for order in orders:
print(f"- Order ID: {order.id}")
print(f" Display name: {order.display_name}")
print(f" Status: {order.status}")
print(f" Order tags: {', '.join(order.tags) if order.tags else 'No tags'}")
# The filter searches for all matching orders
filter = {
"op": "=",
"args": [
{"property": "order_id"},
order.id
],
}
items = UP42_client.search(filter=filter)
found = False
for item in items.items():
collection = item.get_collection()
if not collection:
continue
# Find the asset with the 'original' role
original_delivery = next(
(asset for asset in collection.assets.values()
if asset.roles and "original" in asset.roles),
None,
)
# Download the file
if original_delivery:
downloaded_file_path = original_delivery.file.download(output_directory=output_dir)
print(f"The original delivery for order {order.id} downloaded to '{downloaded_file_path}'.\n")
found = True
break # Only one 'original' asset per order
if not found:
print(f"The original delivery wasn't found for order {order.id}.")
print("All downloads complete.")

Geospatial assets


See all available roles.

Python
import pathlib
# Select a STAC item and the asset role
6 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
role = "data"
# Define a directory to store the downloaded files
output_dir = pathlib.Path.home() / "Desktop" / "data_files"
output_dir.mkdir(parents=True, exist_ok=True)
# Fetch STAC item info
item = UP42_client.get_item(stac_item_id)
# Find all assets with the selected role and download them
download_count = 0
for asset in item.assets.values():
if asset.roles and role in asset.roles:
asset.file.download(output_directory=output_dir)
download_count += 1
print()
# Check the count
if download_count > 0:
print(f"\n{download_count} file(s) downloaded to '{output_dir}'.")
else:
print("\nNo assets of this role were found.")
Python
import pathlib
# Select a STAC item
6 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
file_type = "image/tiff"
# Define a directory to store the downloaded files
output_dir = pathlib.Path.home() / "Desktop" / "tiff_files"
output_dir.mkdir(parents=True, exist_ok=True)
# Fetch STAC item info
item = UP42_client.get_item(stac_item_id)
# Find all assets of the selected format and download them
download_count = 0
for asset in item.assets.values():
if asset.media_type and file_type in asset.media_type:
asset.file.download(output_directory=output_dir)
download_count += 1
print()
# Check the count
if download_count > 0:
print(f"\n{download_count} file(s) downloaded to '{output_dir}'.")
else:
print("\nNo assets of this file format were found.")
Python
import pathlib
# Select an order
14 collapsed lines
order_id = "68567134-27ad-7bd7-4b65-d61adb11fc78"
# Define a directory to store the downloaded files
output_dir = pathlib.Path.home() / "Desktop" / "order_assets"
output_dir.mkdir(parents=True, exist_ok=True)
# The search filter
filter = {
"op": "=",
"args": [
{"property": "order_id"},
order_id,
],
}
# Search for all STAC items from the order
items = UP42_client.search(filter=filter)
# Find and download all assets from all items from the order
download_count = 0
for item in items.items():
print(f"\nProcessing assets for item {item.id}")
for asset in item.assets.values():
print(f"Downloading asset '{asset.title or asset.href}'")
asset.file.download(output_directory=output_dir)
download_count += 1
print()
# Check the count
if download_count > 0:
print(f"{download_count} file(s) downloaded to '{output_dir}'.")
else:
print(f"No items or assets were found for order ID: '{order_id}'.")
Python
import pathlib
# Select a job
14 collapsed lines
job_id = "55434287-31bc-3ad7-1a63-d61aac11ac55"
# Define a directory to store the downloaded files
output_dir = pathlib.Path.home() / "Desktop" / "job_assets"
output_dir.mkdir(parents=True, exist_ok=True)
# The search filter
filter = {
"op": "=",
"args": [
{"property": "job_id"},
job_id,
],
}
# Search for all STAC items from the job
items = UP42_client.search(filter=filter)
# Find and download all assets from all items from the job
download_count = 0
for item in items.items():
print(f"\nProcessing assets for item {item.id}")
for asset in item.assets.values():
print(f"Downloading asset '{asset.title or asset.href}'")
asset.file.download(output_directory=output_dir)
download_count += 1
print()
# Check the count
if download_count > 0:
print(f"{download_count} file(s) downloaded to '{output_dir}'.")
else:
print(f"No items or assets were found for job ID: '{job_id}'.")

Class: Up42Extension

A class that defines a namespace to access data from UP42 STAC extensions.

Attributes

AttributeDescription
title

str

Refers to the up42-user:title property.

tags

str

Refers to the up42-user:tags property.

product_id

str

Refers to the up42-product:product_id property.

collection_name

str

Refers to the up42-product:collection_name property.

modality

str

Refers to the up42-product:modality property.

order_id

str

Refers to the up42-order:id property.

asset_id

str

Refers to the up42-system:asset_id property.

account_id

str

Refers to the up42-system:account_id property.

workspace_id

str

Refers to the up42-system:workspace_id property.

job_id

str

Refers to the up42-system:job_id property.

source

str

Refers to the up42-system:source property.

metadata_version

str

Refers to the up42-system:metadata_version property.

Class: BulkDeletion

A class that deletes entire STAC collections by gathering all of their STAC item IDs into a deletion batch.

All items from a collection must be added for the operation to be successful.

Attributes

AttributeDescription
item_ids

str, …

STAC item IDs to add to the deletion batch. Each ID must be passed separately.

Python
# Select STAC items to delete
item_ids_to_delete = [
"14371401-97a3-4b23-9b55-c3ac10d47750",
"ea36dee9-fed6-457e-8400-2c20ebd30f44",
]
# Initialize the bulk deletion handler and add items
deleter = UP42_client.BulkDeletion(*item_ids_to_delete)
# Submit the deletion request
deleter.delete()

Methods

delete

Submits the batch of staged STAC items to be deleted.

An item can only be deleted if all items of the same STAC collection are added for deletion.

Python
# Select STAC items to delete
item_ids_to_delete = [
"14371401-97a3-4b23-9b55-c3ac10d47750",
"ea36dee9-fed6-457e-8400-2c20ebd30f44",
]
# Initialize the bulk deletion handler and add items
deleter = UP42_client.BulkDeletion(*item_ids_to_delete)
# Submit the deletion request
deleter.delete()

Learn more


Last updated: