Manage geospatial data in your storage with PySTAC.
View repositoryAfter you’ve authenticated with the SDK, create a PySTAC client connection.
UP42_client = up42.stac_client()
The code samples on this page require an initialized UP42_client
object.
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
Attribute | Description |
---|---|
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 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
Provides access to all UP42-specific metadata embedded within the collection.
import json
# Select a STAC collectionstac_collection_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC collection infocollection = UP42_client.get_collection(stac_collection_id)up42_properties = collection.up42
# Define outputreadable_json = json.dumps(up42_properties._reference, indent=2)print(readable_json)
Methods
Retrieves all STAC collections. Returns Iterator[Collection]
. Use itertools.islice
to offset and limit the results. See the PySTAC documentation for more information.
from itertools import islice
# Search for STAC collectionscollections = UP42_client.get_collections()
# Define outputfor 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()
Retrieves a specific STAC collection associated with an item. Returns Collection
. See the PySTAC documentation for more information.
# Select a STAC itemstac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch the parent STAC collectioncollection = UP42_client.get_item(stac_item_id).get_collection()
# Define outputprint(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}")
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
Attribute | Description |
---|---|
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 |
stac_extensions | list[str] Enabled STAC extensions. |
Properties
Provides access to all UP42-specific metadata embedded within the item.
import json
# Select a STAC itemstac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item infoitem = UP42_client.get_item(stac_item_id)up42_properties = item.up42
# Define outputreadable_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.
Parameter | Description |
---|---|
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 | Optional[geojson.Polygon] A polygon in the GeoJSON format. |
datetime | Optional[str] The date and time when the sensor acquired the data. |
from itertools import islice
# Define the search filterfilter = { "op": "=", "args": [ {"property": "order_id"}, # This example searches by order ID "68567134-27ad-7bd7-4b65-d61adb11fc78", # The selected order ID ],}
# Search for STAC itemsitems = UP42_client.search(filter=filter)
# Define output15 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()
Retrieves all STAC items. Returns Iterator[Item]
. Use itertools.islice
to offset and limit the results. See the PySTAC documentation for more information.
from itertools import islice
# Search for STAC itemsitems = UP42_client.get_items()
# Define output15 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()
Retrieves a specific STAC item by its ID. Returns Item
. See the PySTAC documentation for more information.
Parameter | Description |
---|---|
id | str The STAC item ID. |
from itertools import islice
# Select a STAC itemstac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item infoitem = UP42_client.get_item(stac_item_id)
# Define output13 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 jobsprint(f"Order ID: {item.up42.order_id or 'N/A'}") # For ordersprint(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}")
Changes the title and tags of a STAC item.
# Select a STAC itemstac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item infoitem = UP42_client.get_item(stac_item_id)
# Update the title in our databaseitem.up42.title = "Pleiades Berlin"item.update()
# Define output to check the changesprint(f"STAC item ID: {item.id}")print(f"User title: {item.up42.title}")
# Select a STAC itemstac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item infoitem = UP42_client.get_item(stac_item_id)
# Define new tags to addnew_tags = ["ortho-done"]
# Update tags in our databaseitem.up42.tags = item.up42.tags + new_tags # This adds new tags to existing ones# item.up42.tags = ["only-ortho-done"] # Uncomment to overwrite existing tagsitem.update()
# Define output to check the changesprint(f"STAC item ID: {item.id}")print(f"User tags: {item.up42.tags}")
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
Attribute | Description |
---|---|
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
Retrieves the signed URL for the asset file. Returns str
. Uses the file
helper object.
# Select a STAC item4 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch STAC item infoitem = UP42_client.get_item(stac_item_id)
# Find the first asset with the 'multispectral' rolemultispectral_asset = next( (asset for asset in item.assets.values() if asset.roles and "multispectral" in asset.roles), None,)
# Define outputif multispectral_asset: print(f"The signed URL: {multispectral_asset.file.url}")else: print("No asset found.")
Methods
Downloads assets from storage. Uses the file
helper object.
Parameter | Description |
---|---|
output_directory | Union[str, pathlib.Path] The file output directory. |
Original deliveries
import pathlib
# Select a STAC item5 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Define a directory to store the downloaded ZIPoutput_dir = pathlib.Path.home() / "Desktop" / "original_zipped_deliveries"output_dir.mkdir(parents=True, exist_ok=True)
# Fetch the parent STAC collectioncollection = UP42_client.get_item(stac_item_id).get_collection()
# Find the asset with the 'original' roleoriginal_delivery = next( (asset for asset in collection.assets.values() if asset.roles and "original" in asset.roles), None,)
# Download the fileif 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.")
import pathlib
# Define the search filter14 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 itemsitems = UP42_client.search(filter=filter)
# Define a directory to store the downloaded filesoutput_dir = pathlib.Path.home() / "Desktop" / "original_zipped_deliveries"output_dir.mkdir(parents=True, exist_ok=True)
# Fetch the parent STAC collectionsfor 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}'.") breakelse: print(f"The original delivery wasn't found.")
import pathlib
# Define the search criteria8 collapsed lines
orders = up42.Order.all( status=["FULFILLED"], tags=["project-7"],)
# Define a directory to store the downloaded filesoutput_dir = pathlib.Path.home() / "Desktop" / "original_zipped_deliveries"output_dir.mkdir(parents=True, exist_ok=True)
# Process each order21 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.
import pathlib
# Select a STAC item and the asset role6 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"role = "data"
# Define a directory to store the downloaded filesoutput_dir = pathlib.Path.home() / "Desktop" / "data_files"output_dir.mkdir(parents=True, exist_ok=True)
# Fetch STAC item infoitem = UP42_client.get_item(stac_item_id)
# Find all assets with the selected role and download themdownload_count = 0for 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 countif download_count > 0: print(f"\n{download_count} file(s) downloaded to '{output_dir}'.")else: print("\nNo assets of this role were found.")
import pathlib
# Select a STAC item6 collapsed lines
stac_item_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"file_type = "image/tiff"
# Define a directory to store the downloaded filesoutput_dir = pathlib.Path.home() / "Desktop" / "tiff_files"output_dir.mkdir(parents=True, exist_ok=True)
# Fetch STAC item infoitem = UP42_client.get_item(stac_item_id)
# Find all assets of the selected format and download themdownload_count = 0for 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 countif download_count > 0: print(f"\n{download_count} file(s) downloaded to '{output_dir}'.")else: print("\nNo assets of this file format were found.")
import pathlib
# Select an order14 collapsed lines
order_id = "68567134-27ad-7bd7-4b65-d61adb11fc78"
# Define a directory to store the downloaded filesoutput_dir = pathlib.Path.home() / "Desktop" / "order_assets"output_dir.mkdir(parents=True, exist_ok=True)
# The search filterfilter = { "op": "=", "args": [ {"property": "order_id"}, order_id, ],}
# Search for all STAC items from the orderitems = UP42_client.search(filter=filter)
# Find and download all assets from all items from the orderdownload_count = 0for 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 countif 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}'.")
import pathlib
# Select a job14 collapsed lines
job_id = "55434287-31bc-3ad7-1a63-d61aac11ac55"
# Define a directory to store the downloaded filesoutput_dir = pathlib.Path.home() / "Desktop" / "job_assets"output_dir.mkdir(parents=True, exist_ok=True)
# The search filterfilter = { "op": "=", "args": [ {"property": "job_id"}, job_id, ],}
# Search for all STAC items from the jobitems = UP42_client.search(filter=filter)
# Find and download all assets from all items from the jobdownload_count = 0for 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 countif 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}'.")
A class that defines a namespace to access data from UP42 STAC extensions.
Attributes
Attribute | Description |
---|---|
title | str Refers to the |
tags | str Refers to the |
product_id | str Refers to the |
collection_name | str Refers to the |
modality | str Refers to the |
order_id | str Refers to the |
asset_id | str Refers to the |
account_id | str Refers to the |
workspace_id | str Refers to the |
job_id | str Refers to the |
source | str Refers to the |
metadata_version | str Refers to the |
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
Attribute | Description |
---|---|
item_ids | str, … STAC item IDs to add to the deletion batch. Each ID must be passed separately. |
# Select STAC items to deleteitem_ids_to_delete = [ "14371401-97a3-4b23-9b55-c3ac10d47750", "ea36dee9-fed6-457e-8400-2c20ebd30f44",]
# Initialize the bulk deletion handler and add itemsdeleter = UP42_client.BulkDeletion(*item_ids_to_delete)
# Submit the deletion requestdeleter.delete()
Methods
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.
# Select STAC items to deleteitem_ids_to_delete = [ "14371401-97a3-4b23-9b55-c3ac10d47750", "ea36dee9-fed6-457e-8400-2c20ebd30f44",]
# Initialize the bulk deletion handler and add itemsdeleter = UP42_client.BulkDeletion(*item_ids_to_delete)
# Submit the deletion requestdeleter.delete()