Skip to content

Storage

The Storage class enables access to the UP42 storage. You can list your assets and orders within an UP42 workspace.

Use the storage:

storage = up42.initialize_storage()

Methods

get_assets(self, return_json=False)

Gets all assets in the workspace as Asset objects or json.

Parameters:

Name Type Description Default
return_json bool

If set to True, returns json object.

False

Returns:

Type Description
Union[List[up42.asset.Asset], dict]

Asset objects in the workspace or alternatively json info of the assets.

Source code in up42/storage.py
def get_assets(self, return_json: bool = False) -> Union[List[Asset], dict]:
    """
    Gets all assets in the workspace as Asset objects or json.

    Args:
        return_json: If set to True, returns json object.

    Returns:
        Asset objects in the workspace or alternatively json info of the assets.
    """
    url = f"{self.auth._endpoint()}/workspaces/{self.workspace_id}/assets"
    assets_json = self._paginate(url)
    logger.info(f"Got {len(assets_json)} assets for workspace {self.workspace_id}.")

    if return_json:
        return assets_json  # type: ignore
    else:
        assets = [
            Asset(self.auth, asset_id=asset["id"]) for asset in tqdm(assets_json)
        ]
        return assets

get_orders(self, return_json=False)

Gets all orders in the workspace as Order objects or json.

Parameters:

Name Type Description Default
return_json bool

If set to True, returns json object.

False

Returns:

Type Description
Union[List[up42.order.Order], dict]

Order objects in the workspace or alternatively json info of the orders.

Source code in up42/storage.py
def get_orders(self, return_json: bool = False) -> Union[List[Order], dict]:
    """
    Gets all orders in the workspace as Order objects or json.

    Args:
        return_json: If set to True, returns json object.

    Returns:
        Order objects in the workspace or alternatively json info of the orders.
    """
    url = f"{self.auth._endpoint()}/workspaces/{self.workspace_id}/orders"
    response_json = self.auth._request(request_type="GET", url=url)
    orders_json = response_json["data"]["orders"]
    logger.info(f"Got {len(orders_json)} orders for workspace {self.workspace_id}.")

    if return_json:
        return orders_json
    else:
        orders = [
            Order(self.auth, order_id=order["id"]) for order in tqdm(orders_json)
        ]
        return orders