DataVersion

class DataVersion[source]

Bases: supervisely.api.module_api.ModuleApiBase

Class for managing project versions. This class provides methods for creating, restoring, and managing project versions.

Methods

cancel_reservation

Cancel version reservation for a project.

commit

Commit project version.

convert_info_to_json

_convert_info_to_json

create

Create a new project version.

get_id_by_number

Get version ID by version number.

get_info_by_id

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

get_list

Get list of project versions.

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.

get_map

Get project versions map from storage.

info_sequence

NamedTuple VersionInfo with API Fields containing information about Project Version.

info_tuple_name

NamedTuple name - VersionInfo.

initialize

Initialize project versions.

reserve

Reserve project version.

restore

Restore project to a specific version.

set_map

Save project versions map to storage.

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.VersionInfo

cancel_reservation(version_id, commit_token)[source]

Cancel version reservation for a project.

Parameters
version_id : int

Version ID

commit_token : str

Commit token

Returns

True if reservation was cancelled, False otherwise

commit(version_id, commit_token, updated_at, file_id, title=None, description=None)[source]

Commit project version. This method is used to finalize the version creation process. Requires active reservation. You must call this method after creating project version backup and setting version map

Parameters
version_id : int

Version ID

commit_token : str

Commit token

updated_at : str

Updated at timestamp

file_id : int

File ID

title : Optional[str]

Version title

description : Optional[str]

Version description

Returns

None

classmethod convert_info_to_json(info)

_convert_info_to_json

Return type

Dict

create(project_info, version_title=None, version_description=None)[source]

Create a new project version. Returns the ID of the new version. If the project is already on the latest version, returns the latest version ID. If the project version cannot be created, returns None.

Parameters
project_info : Union[ProjectInfo, int]

ProjectInfo object or project ID

version_title : Optional[str]

Version title

version_description : Optional[str]

Version description

Returns

Version ID

Return type

int

get_id_by_number(project_id, version_num)[source]

Get version ID by version number.

Parameters
project_id : int

Project ID

version_num : int

Version number

Returns

Version ID

Return type

int or None

get_info_by_id(id)

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

Parameters
id : int

ID of the entity.

get_list(project_id, filters=None)[source]

Get list of project versions.

Parameters
project_id : int

Project ID

filters : Optional[List]

Filters

Returns

List of project versions

Return type

List[VersionInfo]

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))
get_map(project_info, do_initialization=True)[source]

Get project versions map from storage.

Parameters
project_info : Union[ProjectInfo, int]

ProjectInfo object or project ID

do_initialization : bool

Initialize project versions. Set to False for internal use.

Returns

Project versions

Return type

dict

static info_sequence()[source]

NamedTuple VersionInfo with API Fields containing information about Project Version.

static info_tuple_name()[source]

NamedTuple name - VersionInfo.

initialize(project_info)[source]

Initialize project versions.

Parameters
project_info : Union[ProjectInfo, int]

ProjectInfo object or project ID

reserve(project_id, retries=6)[source]

Reserve project version. This method is used before backing up a version to prevent another attempt to create a version at the same time. The first delay of retry is 2 seconds, which doubles with each subsequent attempt.

Parameters
project_id : int

Project ID

retries : int

Number of attempts to reserve version

Returns

Version ID and commit token

Return type

Tuple[int, str]

restore(project_info, version_id=None, version_num=None, skip_missed_entities=False)[source]

Restore project to a specific version. Version can be specified by ID or number.

Parameters
project_info : Union[ProjectInfo, int]

ProjectInfo object or project ID

version_id : Optional[int]

Version ID

version_num : Optional[int]

Version number

skip_missed_entities : bool, default False

Skip missed Images

Returns

ProjectInfo object of the restored project

Return type

ProjectInfo or None

set_map(project_info, initialize=True)[source]

Save project versions map to storage.

Parameters
project_info : Union[ProjectInfo, int]

ProjectInfo object or project ID

initialize : bool

Initialize project versions. Set to False for internal use.

Returns

None