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 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. |
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 file if foundif original_delivery: downloaded_file_path = original_delivery.file.download(output_directory=output_dir) print(f"\nThe original delivery downloaded to '{output_dir}'.")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 files if found if original_delivery: downloaded_file_path = original_delivery.file.download(output_directory=output_dir) print(f"\nThe original delivery was downloaded to '{output_dir}'.") breakelse: print(f"The original delivery wasn't found.")
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 |