Skip to content

Order

The Order class enables you to place, inspect and get information on orders.

Use an existing order:

order = up42.initialize_order(order_id="ea36dee9-fed6-457e-8400-2c20ebd30f44")

Attributes

info: dict property readonly

Gets the Order information.

is_fulfilled: bool property readonly

Gets True if the order is fulfilled, False otherwise. Also see status attribute.

metadata: dict property readonly

Gets the Order metadata.

status: str property readonly

Gets the Order status. One of PLACED, FAILED, FULFILLED, BEING_FULFILLED, FAILED_PERMANENTLY.

Methods

estimate(auth, data_provider_name, order_params) staticmethod

Returns an estimation of the cost of an order.

Parameters:

Name Type Description Default
auth Auth

An authentication object.

required
data_provider_name str

The data provider name. Currently only oneatlas is a supported provider.

required
order_params dict

Order definition, including id and aoi.

required

Returns:

Type Description
int
Source code in up42/order.py
@staticmethod
def estimate(auth: Auth, data_provider_name: str, order_params: dict) -> int:
    """
    Returns an estimation of the cost of an order.

    Args:
        auth: An authentication object.
        data_provider_name: The data provider name. Currently only `oneatlas` is a supported provider.
        order_params: Order definition, including `id` and `aoi`.

    Returns:
        int: The estimated cost of the order
    """
    assert (
        data_provider_name in DATA_PROVIDERS
    ), f"Currently only {DATA_PROVIDERS} are supported as a data provider."
    url = f"{auth._endpoint()}/workspaces/{auth.workspace_id}/orders/estimate"
    payload = {
        "dataProviderName": data_provider_name,
        "orderParams": order_params,
    }

    response_json = auth._request(request_type="POST", url=url, data=payload)
    estimated_credits: int = response_json["data"]["credits"]  # type: ignore
    logger.info(
        f"Order with order parameters {payload} is estimated to cost {estimated_credits} UP42 credits."
    )
    return estimated_credits

get_assets(self)

Gets the Order assets or results.

Source code in up42/order.py
def get_assets(self) -> List[Asset]:
    """
    Gets the Order assets or results.
    """
    if self.is_fulfilled:
        assets: List[str] = self.info["assets"]
        return [Asset(self.auth, asset_id=asset) for asset in assets]
    raise ValueError(
        f"Order {self.order_id} is not FULFILLED! Status is {self.status}"
    )

place(auth, data_provider_name, order_params) classmethod

Places an order.

Parameters:

Name Type Description Default
auth Auth

An authentication object.

required
data_provider_name str

The data provider name. Currently only oneatlas is a supported provider.

required
order_params dict

Order definition, including id and aoi.

required

Returns:

Type Description
Order
Source code in up42/order.py
@classmethod
def place(cls, auth: Auth, data_provider_name: str, order_params: dict) -> "Order":
    """
    Places an order.

    Args:
        auth: An authentication object.
        data_provider_name: The data provider name. Currently only `oneatlas` is a supported provider.
        order_params: Order definition, including `id` and `aoi`.

    Returns:
        Order: The placed order.
    """
    assert (
        data_provider_name in DATA_PROVIDERS
    ), f"Currently only {DATA_PROVIDERS} are supported as a data provider."
    order_payload = {
        "dataProviderName": data_provider_name,
        "orderParams": order_params,
    }
    url = f"{auth._endpoint()}/workspaces/{auth.workspace_id}/orders"
    response_json = auth._request(request_type="POST", url=url, data=order_payload)
    try:
        order_id = response_json["data"]["id"]  # type: ignore
    except KeyError as e:
        raise ValueError(f"Order was not placed: {response_json}") from e
    order = cls(auth=auth, order_id=order_id, payload=order_payload)
    logger.info(f"Order {order.order_id} is now {order.status}.")
    return order

track_status(self, report_time=120)

Continuously gets the order status until order is fulfilled or failed.

Internally checks every report_time (s) for the status and prints the log.

Warning

When placing orders of items that are in archive or cold storage, the order fulfillment can happen up to 24h after order placement. In such cases, please make sure to set an appropriate report_time.

Parameters:

Name Type Description Default
report_time int

The interval (in seconds) when to get the order status.

120

Returns:

Type Description
str
Source code in up42/order.py
def track_status(self, report_time: int = 120) -> str:
    """
    Continuously gets the order status until order is fulfilled or failed.

    Internally checks every `report_time` (s) for the status and prints the log.

    Warning:
        When placing orders of items that are in archive or cold storage,
        the order fulfillment can happen up to **24h after order placement**.
        In such cases,
        please make sure to set an appropriate `report_time`.

    Args:
        report_time: The interval (in seconds) when to get the order status.

    Returns:
        str: The final order status.
    """
    logger.info(
        f"Tracking order status, reporting every {report_time} seconds...",
    )
    time_asleep = 0

    while not self.is_fulfilled:
        status = self.status
        if status in ["PLACED", "BEING_FULFILLED"]:
            if time_asleep != 0 and time_asleep % report_time == 0:
                logger.info(f"Order is {status}! - {self.order_id}")
        elif status in ["FAILED", "FAILED_PERMANENTLY"]:
            logger.info(f"Order is {status}! - {self.order_id}")
            raise ValueError("Order has failed!")

        sleep(report_time)
        time_asleep += report_time

    logger.info(f"Order is fulfilled successfully! - {self.order_id}")
    return self.status