EntitiesCollectionApi

class EntitiesCollectionApi[source]

Bases: supervisely.api.module_api.UpdateableModule, supervisely.api.module_api.RemoveableModuleApi

API for working with Entities Collection. EntitiesCollectionApi object is immutable.

Parameters
api : Api

API connection to the server.

Usage example
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api.from_env()

# Pass values into the API constructor (optional, not recommended)
# api = sly.Api(server_address="https://app.supervisely.com", token="4r47N...xaTatb")

collection = api.entities_collection.get_list(9) # api usage example

Methods

add_items

Add items to Entities Collection.

convert_info_to_json

_convert_info_to_json

create

Creates Entities Collections.

exists

Checks if an entity with the given parent_id and name exists

get_free_name

Generates a free name for an entity with the given parent_id and name.

get_info_by_id

Get information about Entities Collection with given ID.

get_info_by_name

Get information about an entity by its name from the Supervisely server.

get_items

Get items from Entities Collection.

get_list

Get list of information about Entities Collection for the given project.

get_list_all_pages

Get list of all or limited quantity entities from the Supervisely server.

get_list_all_pages_generator

This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved

get_list_idx_page_async

Get the list of items for a given page number.

get_list_page_generator_async

Yields list of images in dataset asynchronously page by page.

info_sequence

NamedTuple EntitiesCollectionInfo information about Entities Collection.

info_tuple_name

NamedTuple name - EntitiesCollectionInfo.

remove

Remove an entity with the specified ID from the Supervisely server.

remove_batch

Remove entities with given IDs from the Supervisely server.

remove_items

Remove items from Entities Collection.

update

Attributes

MAX_WAIT_ATTEMPTS

Maximum number of attempts that will be made to wait for a certain condition to be met.

WAIT_ATTEMPT_TIMEOUT_SEC

Number of seconds for intervals between attempts.

InfoType

alias of supervisely.api.module_api.EntitiesCollectionInfo

add_items(id, items)[source]

Add items to Entities Collection.

Parameters
id : int

Entities Collection ID in Supervisely.

items : List[int]

List of item IDs in Supervisely.

Usage example
import supervisely as sly

os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

collection_id = 2
item_ids = [525, 526]
new_items = api.entities_collection.add_items(collection_id, item_ids)
print(new_items)
# Output: [
#   {"id": 1, "entityId": 525, 'createdAt': '2025-04-10T08:49:41.852Z'},
#   {"id": 2, "entityId": 526, 'createdAt': '2025-04-10T08:49:41.852Z'}
]
Return type

List[Dict[str, int]]

classmethod convert_info_to_json(info)

_convert_info_to_json

Return type

Dict

create(project_id, name, description=None)[source]

Creates Entities Collections.

Parameters
project_id : int

Project ID in Supervisely.

name : str

Entities Collection name in Supervisely.

description : str

Entities Collection description.

Returns

Information about new Entities Collection

Return type

EntitiesCollectionInfo

Usage example
import supervisely as sly

os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

user_name = 'Collection #1'
project_id = 602
new_collection = api.entities_collection.create(name, project_id)
print(new_collection)
exists(parent_id, name)

Checks if an entity with the given parent_id and name exists

Parameters
parent_id : int

ID of the parent entity.

name : str

Name of the entity.

Returns

Returns True if entity exists, and False if not

Return type

bool

Usage example
import supervisely as sly

# You can connect to API directly
address = 'https://app.supervisely.com/'
token = 'Your Supervisely API Token'
api = sly.Api(address, token)

# Or you can use API from environment
os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()


name = "IMG_0315.jpeg"
dataset_id = 55832
exists = api.image.exists(dataset_id, name)
print(exists) # True
get_free_name(parent_id, name)

Generates a free name for an entity with the given parent_id and name. Adds an increasing suffix to original name until a unique name is found.

Parameters
parent_id : int

ID of the parent entity.

name : str

Name of the entity.

Returns

Returns free name.

Return type

str

Usage example
import supervisely as sly

# You can connect to API directly
address = 'https://app.supervisely.com/'
token = 'Your Supervisely API Token'
api = sly.Api(address, token)

# Or you can use API from environment
os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()


name = "IMG_0315.jpeg"
dataset_id = 55832
free_name = api.image.get_free_name(dataset_id, name)
print(free_name) # IMG_0315_001.jpeg
get_info_by_id(id)[source]

Get information about Entities Collection with given ID.

Parameters
id : int

Entities Collection ID in Supervisely.

Returns

Information about Entities Collection.

Return type

EntitiesCollectionInfo

Usage example

import supervisely as sly

os.environ[‘SERVER_ADDRESS’] = ‘https://app.supervisely.com’ os.environ[‘API_TOKEN’] = ‘Your Supervisely API Token’ api = sly.Api.from_env()

collection = api.entities_collection.get_info_by_id(2) print(collection) # Output: # { # “id”: 1, # “teamId”: 1, # “projectId”: 1, # “name”: “ds”, # “description”: “”, # “createdAt”: “2018-08-21T14:25:56.140Z”, # “updatedAt”: “2018-08-21T14:25:56.140Z” # }

get_info_by_name(parent_id, name, fields=[])

Get information about an entity by its name from the Supervisely server.

Parameters
parent_id : int

ID of the parent entity.

name : str

Name of the entity for which the information is being retrieved.

fields : List[str]

The list of api fields which will be returned with the response.

Usage example
import supervisely as sly

# You can connect to API directly
address = 'https://app.supervisely.com/'
token = 'Your Supervisely API Token'
api = sly.Api(address, token)

# Or you can use API from environment
os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()


dataset_id = 55832
name = "IMG_0315.jpeg"
info = api.image.get_info_by_name(dataset_id, name)
print(info)
# Output: ImageInfo(id=19369643, name='IMG_0315.jpeg', ...)
get_items(id, project_id=None)[source]

Get items from Entities Collection.

Parameters
id : int

Entities Collection ID in Supervisely.

project_id : int, optional

Project ID in Supervisely.

Returns

List of item IDs in Supervisely.

Return type

List[int]

Raises

RuntimeError – If Entities Collection with given ID not found.

Usage example
import supervisely as sly

os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

collection_id = 2
project_id = 4
item_ids = api.entities_collection.get_items(collection_id, project_id)
print(item_ids)
get_list(project_id, filters=None)[source]

Get list of information about Entities Collection for the given project.

Parameters
project_id : int, optional

Project ID in Supervisely.

Returns

List of information about Entities Collections.

Return type

List[EntitiesCollectionInfo]

Usage example
import supervisely as sly

os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

collections = api.entities_collection.get_list(4)
get_list_all_pages(method, data, progress_cb=None, convert_json_info_cb=None, limit=None, return_first_response=False)

Get list of all or limited quantity entities from the Supervisely server.

Parameters
method : str

Request method name

data : dict

Dictionary with request body info

progress_cb : Progress, optional

Function for tracking download progress.

convert_json_info_cb : Callable, optional

Function for convert json info

limit : int, optional

Number of entity to retrieve

return_first_response : bool, optional

Specify if return first response

get_list_all_pages_generator(method, data, progress_cb=None, convert_json_info_cb=None, limit=None, return_first_response=False)

This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved

Parameters
method : str

Request method name

data : dict

Dictionary with request body info

progress_cb : Progress, optional

Function for tracking download progress.

convert_json_info_cb : Callable, optional

Function for convert json info

limit : int, optional

Number of entity to retrieve

return_first_response : bool, optional

Specify if return first response

async get_list_idx_page_async(method, data)

Get the list of items for a given page number. Page number is specified in the data dictionary.

Parameters
method : str

Method to call for listing items.

data : dict

Data to pass to the API method.

Returns

List of items.

Return type

Tuple[int, List[NamedTuple]]

async get_list_page_generator_async(method, data, pages_count=None, semaphore=None)

Yields list of images in dataset asynchronously page by page.

Parameters
method : str

Method to call for listing items.

data : dict

Data to pass to the API method.

pages_count : int, optional

Preferred number of pages to retrieve if used with a per_page limit. Will be automatically adjusted if the pagesCount differs from the requested number.

semaphore : asyncio.Semaphore, optional

Semaphore for limiting the number of simultaneous requests.

kwargs

Additional arguments.

Returns

List of images in dataset.

Return type

AsyncGenerator[List[ImageInfo]]

Usage example
import supervisely as sly
import asyncio

os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

method = 'images.list'
data = {
    'datasetId': 123456
}

loop = sly.utils.get_or_create_event_loop()
images = loop.run_until_complete(api.image.get_list_generator_async(method, data))
static info_sequence()[source]

NamedTuple EntitiesCollectionInfo information about Entities Collection.

Example
 EntitiesCollectionInfo(
    id=2,
    name='Enitites Collections #1',
    team_id=4,
    project_id=58,
    description='',
    created_at='2020-04-08T15:10:12.618Z',
    updated_at='2020-04-08T15:10:19.833Z',
)
static info_tuple_name()[source]

NamedTuple name - EntitiesCollectionInfo.

remove(id)

Remove an entity with the specified ID from the Supervisely server.

Parameters
id : int

Entity ID in Supervisely

remove_batch(ids, progress_cb=None)

Remove entities with given IDs from the Supervisely server.

Parameters
ids : List[int]

IDs of entities in Supervisely.

progress_cb : Callable

Function for control remove progress.

remove_items(id, items)[source]

Remove items from Entities Collection.

Parameters
id : int

Entities Collection ID in Supervisely.

items : List[int]

List of item IDs in Supervisely.

Usage example
import supervisely as sly
api = sly.Api.from_env()

collection_id = 2
item_ids = [525, 526, 527]
removed_items = api.entities_collection.remove_items(collection_id, item_ids)
# print(removed_items)
# Output: [{"id": 1, "entityId": 525}, {"id": 2, "entityId": 526}]
Return type

List[Dict[str, int]]

update(id, name=None, description=None)