DataVersion¶
- class DataVersion(api)[source]¶
Bases:
ModuleApiBaseClass for managing project versions. This class provides methods for creating, restoring, and managing project versions.
Class for managing project versions.
Methods
Cancel version reservation for a project.
Commit project version.
Convert information about an entity to a dictionary.
Create a new project version.
Enable preview for the version by creating a snapshot project and linking it to the version.
Get version ID by version number.
Get project version information by version ID.
Get project version information by version number.
Get list of project versions.
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.
Get project versions map from storage.
Get or create a hidden workspace for storing preview project versions for a team.
NamedTuple VersionInfo with API Fields containing information about Project Version.
NamedTuple name - VersionInfo.
Initialize project versions.
Reserve project version.
Restore project to a specific version.
Save project versions map to storage.
Update version information such as name, description or link preview project to the version.
Attributes
MAX_WAIT_ATTEMPTSMaximum number of attempts that will be made to wait for a certain condition to be met.
PROJECT_DESC_TEMPLATEPROJECT_NAME_TEMPLATEWAIT_ATTEMPT_TIMEOUT_SECNumber of seconds for intervals between attempts.
project_cls- InfoType¶
alias of
VersionInfo
- static info_sequence()[source]¶
NamedTuple VersionInfo with API Fields containing information about Project Version.
- cancel_reservation(version_id, commit_token)[source]¶
Cancel version reservation for a project.
-
commit(version_id, commit_token, updated_at, file_id, title=
None, description=None, preview_project_id=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
- preview_project_id : Optional[int]¶
ID of the cloned project that will be used to preview version data.
- Returns:
None
-
create(project_info, version_title=
None, version_description=None, enable_preview=False)[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¶
Project info object or project ID
- version_title : Optional[str]¶
Version title
- version_description : Optional[str]¶
Version description
- enable_preview : bool¶
Enable preview flag that creates clone of the project to hidden workspace making version data available immediately. This option can be used to avoid waiting for version data to be processed on the server before previewing it. Only versions of projects with types VIDEO and IMAGE are supported for preview.
- Returns:
Version ID
- Return type:
-
enable_preview(project, version_id, overwrite=
False, local_binary_path=None)[source]¶ Enable preview for the version by creating a snapshot project and linking it to the version. If the snapshot project already exists and overwrite is False, returns the existing snapshot project ID.
ATTENTION: This method works only for committed versions with successfully uploaded version data.
- Parameters:
- Returns:
Preview snapshot project information
- Return type:
ProjectInfo
- get_id_by_number(project_id, version_num)[source]¶
Get version ID by version number.
- get_info_by_id(project_id, version_id)[source]¶
Get project version information by version ID.
- Parameters:
- Returns:
Project version information
- Return type:
Optional[
VersionInfo]
- get_info_by_number(project_id, version_num)[source]¶
Get project version information by version number.
- Parameters:
- Returns:
Project version information
- Return type:
Optional[
VersionInfo]
-
get_list(project_id, filters=
None)[source]¶ Get list of project versions.
- Parameters:
- 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
- Returns:
List of entities.
- Return type:
List[dict]
-
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=
None¶ Semaphore for limiting the number of simultaneous requests.
- Returns:
List of images in dataset.
- Return type:
AsyncGenerator[List[
ImageInfo]]- 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() 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.
-
get_or_create_versions_workspace(team_id, description=
'')[source]¶ Get or create a hidden workspace for storing preview project versions for a team.
- initialize(project_info)[source]¶
Initialize project versions.
- Parameters:
- project_info¶
Project info 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.
-
restore(project_info, version_id=
None, version_num=None, skip_missed_entities=False, workspace_id=None, project_name=None, project_description=None, local_binary_path=None)[source]¶ Restore project to a specific version. Version can be specified by ID or number.
- Parameters:
- project_info¶
Project info 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
- workspace_id : Optional[int]¶
Workspace ID where the restored project will be created. If None, the project will be restored to the same workspace.
- project_name : Optional[str]¶
Name of the restored project. If None, a default name will be used.
- project_description : Optional[str]¶
Description of the restored project. If None, a default description will be used.
- local_binary_path : Optional[str]¶
Path to the local binary file to restore from. If None, will download from the server.
- Returns:
Project info object of the restored project
- Return type:
ProjectInfoor None
-
set_map(project_info, initialize=
True)[source]¶ Save project versions map to storage.
-
update(version_id, name=
None, description=None, preview_project_id=None)[source]¶ Update version information such as name, description or link preview project to the version.
ATTENTION: Do not use
preview_project_idparameter to link a regular project as it can cause issues with version data consistency. This parameter is intended to link a cloned project in the hidden workspace that is created when enabling preview for the version. Only versions of projects with types VIDEO and IMAGE are supported for preview.- Parameters:
- version_id : int¶
Version ID
- name : Optional[str]¶
New name
- description : Optional[str]¶
New description
- preview_project_id : Optional[int]¶
Preview project ID to link to the version. This project will be used to preview version data. Only versions of projects with types VIDEO and IMAGE are supported for preview.
- Returns:
None
- Return type:
None