EntitiesCollectionApi¶
- class EntitiesCollectionApi[source]¶
Bases:
supervisely.api.module_api.UpdateableModule,supervisely.api.module_api.RemoveableModuleApiAPI for working with Entities Collection.
EntitiesCollectionApiobject 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 to Entities Collection.
_convert_info_to_json
Creates Entities Collections.
Checks if an entity with the given parent_id and name exists
Generates a free name for an entity with the given parent_id and name.
Get information about Entities Collection of type
CollectionType.AI_SEARCHwith given AI search key.Get information about Entities Collection with given ID.
Get information about an entity by its name from the Supervisely server.
Get items from Entities Collection.
Get list of information about Entities Collection for the given project.
Get list of all or limited quantity entities from the Supervisely server.
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 the list of items for a given page number.
Yields list of images in dataset asynchronously page by page.
NamedTuple EntitiesCollectionInfo information about Entities Collection.
Get string name of
EntitiesCollectionInfoNamedTuple.Remove Entites Collection with the specified ID from the Supervisely server.
Remove entities with given IDs from the Supervisely server.
Remove items from Entities Collection.
Attributes
MAX_WAIT_ATTEMPTSMaximum number of attempts that will be made to wait for a certain condition to be met.
WAIT_ATTEMPT_TIMEOUT_SECNumber 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
- Returns
List of added items with their IDs and creation timestamps.
- Return type
- Usage example
import supervisely as sly from supervisely.api.entities_collection_api import CollectionItem 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] items = [CollectionItem(entity_id=item_id) for item_id in item_ids] new_items = api.entities_collection.add_items(collection_id, items) 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'} ]
-
create(project_id, name, description=
None, type='default', ai_search_key=None)[source]¶ Creates Entities Collections.
- Parameters
- 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() project_id = 123 name = "Chihuahuas" description = "Collection of Chihuahuas" type = CollectionType.AI_SEARCH ai_search_key = "0ed6a5256433bbe32822949d563d476a" new_collection = api.entities_collection.create(project_id, name, description, type, ai_search_key) print(new_collection)
- exists(parent_id, name)¶
Checks if an entity with the given parent_id and name exists
- Parameters
- Returns
Returns True if entity exists, and False if not
- Return type
- 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
- Returns
Returns free name.
- Return type
- 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_ai_search_key(project_id, ai_search_key)[source]¶
Get information about Entities Collection of type
CollectionType.AI_SEARCHwith given AI search key.
-
get_info_by_id(id, with_meta=
False)[source]¶ Get information about Entities Collection with given ID.
- Parameters
- 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
- 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(collection_id, collection_type, project_id=
None, ai_search_threshold=None, ai_search_threshold_direction='above')[source]¶ Get items from Entities Collection.
- Parameters
- collection_id : int
Entities Collection ID in Supervisely.
- collection_type : CollectionTypeFilter
Type of the collection. Can be CollectionTypeFilter.AI_SEARCH or CollectionTypeFilter.DEFAULT.
- project_id : int, optional
Project ID in Supervisely.
- ai_search_threshold : float, optional
AI search threshold for filtering items. Optional, defaults to None.
- ai_search_threshold_direction : str
Direction for the AI search threshold. Optional, defaults to ‘above’.
- Returns
List of ImageInfo objects.
- Return type
List[ImageInfo]
- 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, with_meta=False, collection_type='default')[source]¶ Get list of information about Entities Collection for the given project.
- Parameters
- project_id : int, optional
Project ID in Supervisely.
- filters : List[Dict[str, str]], optional
List of filters to apply to the request. Optional, defaults to None.
- with_meta : bool, optional
If True, includes meta information in the response. Defaults to False.
- collection_type : CollectionType
Type of the collection. Defaults to CollectionType.DEFAULT.
- Available types are:
CollectionType.DEFAULT
CollectionType.AI_SEARCH
CollectionType.ALL
- 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.
-
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_pagelimit. Will be automatically adjusted if thepagesCountdiffers 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]¶
Get string name of
EntitiesCollectionInfoNamedTuple.- Returns
NamedTuple name.
- Return type
-
remove(id, force=
False)[source]¶ Remove Entites Collection with the specified ID from the Supervisely server.
If
forceis set to True, the collection will be removed permanently. Ifforceis set to False, the collection will be disabled instead of removed.
-
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
- 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
-
update(id, name=
None, description=None)¶