Python Examples
A pre-requisite for exchanging requests with the Delivery API endpoints is to have a valid authentication token and contract_id
, see Authentication API. In the examples below, the headers in the requests have placeholders for token and contract_id
.
For further reference on usage of task management steps in this example, refer to the Tasking API / Python examples.
import requests
import json
# 0. Complete the following section with your contract_id and access token
#contract_id = ""
#ACCESS_TOKEN = ""
# 1. Get the published captures for a task
ALEPH_API_URL = "https://api.satellogic.com"
tasks_uri = "/tasking/tasks/"
captures_uri = "/captures/"
task_id = 268095
response = requests.get(
f"{ALEPH_API_URL}{tasks_uri}{task_id}{captures_uri}",
headers={
'AuthorizationToken': f'Bearer {ACCESS_TOKEN}',
'X-Satellogic-Contract-Id': contract_id,
},
)
# Raise an error if the request failed
response.raise_for_status()
# Convert response so JSON
captures = response.json()
# Keep only captures that are in status published
published_capture_ids = [
capture["capture_id"]
for capture in captures["results"]
if capture["status"] == "published"
]
print(published_capture_ids)
Sample output:
['a0ab38b2-8cca-4f27-8c18-4c79c6f91cbe',
'6b4901f0-530b-4527-9e31-8624d8d7864b',
'23fa3ed3-08e8-4dfe-a9a3-c5da817599be',
'75492c98-9d9e-412a-bdd3-208bc2d7a5f3']
# 2. Obtain the scene IDs for the first published capture
# Note: sceneset_id is the same as capture_id in this context
# Note: scenes are the deliverables for a capture
sceneset_id = published_capture_ids[0]
scenes_delivery_uri = "/telluric/scenes/"
response = requests.get(
f"{ALEPH_API_URL}{scenes_delivery_uri}?sceneset_id={sceneset_id}",
headers={
'AuthorizationToken': f'Bearer {ACCESS_TOKEN}',
'X-Satellogic-Contract-Id': contract_id,
},
)
# Raise an error if the request failed
response.raise_for_status()
# Convert response to JSON
scenes = response.json()
# Extract all scene IDs from the scenes response
scene_ids = [scene["scene_id"] for scene in scenes["results"]]
# Print the list of scene IDs
print(f"Found {len(scene_ids)} scenes (deliverables), their IDs are:")
for i, scene_id in enumerate(scene_ids, 1):
print(f"{i}. {scene_id}")
Sample output:
Found 2 scenes (deliverables), their IDs are:
1. 20241206_081221_SN49_L1C_MS_268095
2. 20241206_081220_SN49_L1D_MS_268095
# 3. Obtain a download link for the first scene (deliverable)
scene_id = scene_ids[0]
download_link_uri = "/attachments/delivery_zip/download/?redirect=false"
response = requests.get(
f"{ALEPH_API_URL}{scenes_delivery_uri}{scene_id}{download_link_uri}",
headers={
'AuthorizationToken': f'Bearer {ACCESS_TOKEN}',
'X-Satellogic-Contract-Id': contract_id,
},
)
# Raise an error if the request failed
response.raise_for_status()
# Convert response to JSON
download_link = response.json()
print("Download link for the first scene (deliverable):")
print(json.dumps(download_link, indent=4, sort_keys=True))
Sample output: