get_assets

imerit_ango.sdk.SDK.

get_assets(project_id, page, limit, filters)

Get details of assets from a project.

Parameters

  • project_id: string

  • page: integer, default 1

  • limit: integer, default 10

  • filters: dict, default {}

    • By default, all assets will be returned. By including a dict filter here, you may filter the assets you receive.

    • Here is a list of possible filters you may pass in the filters dict:

{
    _id : str, # A specific Asset ID to get.
    externalId: str, # A specific externalId to get.
    isPreLabeled: bool,
    batches: ["<batch_id_1>", "<batch_id_2>"] # When including multiple batches, only the assets belonging to BOTH (all) batches will be returned. This is an "AND" operation.
    createdAt: {"gt": "<ISO_TIME_STR>"}, # gt: Greater Than (after), lt: Less Than (before), ISO_TIME_STR example: 2002-12-09T00:00:00.000Z
    createdAt: {"lt": "<ISO_TIME_STR>"}
}

Returns:

  • output: dict

Example

Retrieve the first ten assets from the project:

import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

sdk_response = ango_sdk.get_assets(project_id)

data_url = sdk_response['data']['assets'][0]['data']
external_id = sdk_response['data']['assets'][0]['externalId']

Retrieve all assets from the project:

import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

page = 1
num_assets = 1
asset_list = []
while len(asset_list) < num_assets:
    response = ango_sdk.get_assets(project_id=project_id, page=page, limit=50)
    assets = response.get('data', {}).get('assets', [])
    num_tasks = response.get('data', {}).get('total', 0)

    asset_list.extend(assets)
    page += 1

print("The number of retrieved assets is: " + str(len(asset_list)))

Retrieve a single asset via asset ID:

import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

asset_id = 'YOUR_ASSET_ID'

ango_sdk = SDK(api_key)

sdk_response = ango_sdk.get_assets(project_id, filters={"_id": asset_id})

data_url = sdk_response['data']['assets'][0]['data']
external_id = sdk_response['data']['assets'][0]['externalId']

Last updated