SDK quick start

Learn your way around the UP42 platform using the SDK.


Step 1. Install dependencies and authenticate

Python

    !pip install up42-py --upgrade -q

import up42, geojson, pathlib
from datetime import date

  

Fill out the configuration file. Check that the authentication was successful as follows:

Python

    up42.authenticate(cfg_file="credentials.json")

  

Step 2. Find scenes from Sentinel-2

Python

    geometry = {
    "type": "Polygon",
    "coordinates": [[
        [13.369713, 52.452327], [13.369713, 52.470760],
        [13.339159, 52.470760], [13.339159, 52.452327],
        [13.369713, 52.452327]
    ]]
}

collections = up42.ProductGlossary.get_collections(
    collection_type=up42.CollectionType.ARCHIVE,
    sort_by=up42.CollectionSorting.name
)
collection = next(c for c in collections if c.name == "sentinel-2")
data_product = next(p for p in collection.data_products if "sentinel-2-level-2a" in p.name)
host = next(p for p in collection.providers if p.is_host)

scenes = list(host.search(
    collections=[collection.name],
    intersects=geometry,
    start_date="2023-06-01",
    end_date="2024-12-31",
    query={"cloudCoverage": {"LT": 10}}
))

scene = scenes[0]

  

Step 3. Create an order

Estimate the price of a potential order in credits:

Python

    order_template = up42.BatchOrderTemplate(
    data_product_id=data_product.id,
    display_name=f"{data_product.name}-{date.today()}",
    features=geojson.FeatureCollection(features=[geojson.Feature(geometry=geometry)]),
    params={"id": scene.id},
    tags=["sdk", data_product.name]
)

order_template.estimate

  

Create an order and track its status:

Python

    order_references = order_template.place()
order = order_references[0].order
order.track()

  

Step 4. Stream files

Python

    UP42_client = up42.stac_client()

filter = {
    "op": "=",
    "args": [
        {"property": "order_id"},
        order.id,
    ],
}

stac_items_search = UP42_client.search(filter=filter)
item = next(stac_items_search.items())

asset = item.assets.get("b02.tiff")
asset.file

  

Last updated: