AppApi¶
- class AppApi[source]¶
Bases:
supervisely.api.task_api.TaskApiAppApi
Methods
_convert_info_to_json
- rtype
Deploy a custom model based on the artifacts directory.
deploy_model_app- rtype
deploy_model_from_apiGet context information by task ID.
Returns ecosystem module id by slug.
Returns ModuleInfo object by module id and version.
- type id
Get list of applications for the specified team.
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_list_ecosystem_modulesGet the list of items for a given page number.
Yields list of images in dataset asynchronously page by page.
Get list of sessions (tasks) for the specified team and module.
get_status- rtype
Checks if app is ready for API calls.
Raise error if Task status is ERROR.
- rtype
- rtype
- rtype
- rtype
Set custom error message to the task output.
Sets output for the task with experiment info.
- rtype
- rtype
- rtype
Set custom text message to the task output.
start- rtype
SessionInfo
- rtype
- rtype
Update given task metadata :type id:
int:param id: int — task id :type data:dict:param data: dict — meta data to updateSets the specified status for the task.
Waits until app is ready for API calls.
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.AppInfo
- class PluginTaskType¶
Bases:
supervisely.collection.str_enum.StrEnumPluginTaskType
- class RestartPolicy¶
Bases:
supervisely.collection.str_enum.StrEnumRestartPolicy
- class Status¶
Bases:
supervisely.collection.str_enum.StrEnumStatus
- class Workflow[source]¶
Bases:
objectThe workflow functionality is used to create connections between the states of projects and tasks (application sessions) that interact with them in some way. By assigning connections to various entities, the workflow tab allows tracking the history of project changes. The active task always acts as a node, for which input and output elements are defined. There can be multiple input and output elements. A task can also be used as an input or output element. For example, an inference task takes a deployed model and a project as inputs, and the output is a new state of the project. This functionality uses versioning optionally.
If instances are not compatible with the workflow features, the functionality will be disabled.
- Parameters
- api : supervisely.api.api.Api
Supervisely API object
- min_instance_version : str
Minimum version of the instance that supports workflow features
-
add_input_dataset(dataset, task_id=
None, meta=None)[source]¶ Add input type “dataset” to the workflow node. This type is used to show that the application has used the specified dataset. Customization of the dataset node is not supported and will be ignored. You can only customize the main node with this method.
- Parameters
- Returns
Response from the API.
- Return type
-
add_input_file(file, model_weight=
False, task_id=None, meta=None)[source]¶ Add input type “file” to the workflow node. This type is used to show that the application has used the specified file.
- Parameters
- file : Union[int, FileInfo, str]
File ID, FileInfo object or file path in team Files.
- model_weight : bool
Flag to indicate if the file is a model weight.
- task_id : Optional[int]
Task ID. If not specified, the task ID will be determined automatically.
- meta : Optional[Union[WorkflowMeta, dict]]
Additional data for node customization.
- Returns
Response from the API.
- Return type
-
add_input_folder(path, task_id=
None, meta=None)[source]¶ Add input type “folder” to the workflow node. Path to the folder is a path in Team Files. This type is used to show that the application has used files from the specified folder.
-
add_input_job(id, task_id=
None, meta=None)[source]¶ Add input type “job” to the workflow node. Job is a Labeling Job. This type indicates that the application has utilized a labeling job during its operation.
-
add_input_project(project=
None, version_id=None, version_num=None, task_id=None, meta=None)[source]¶ Add input type “project” to the workflow node. The project version can be specified to indicate that the project version was used especially for this task. Arguments project and version_id are mutually exclusive. If both are specified, version_id will be used. Argument version_num can only be used in conjunction with the project. This type is used to show that the application has used the specified project. Customization of the project node is not supported and will be ignored. You can only customize the main node with this method.
- Parameters
- project : Optional[Union[int, ProjectInfo]]
Project ID or ProjectInfo object.
- version_id : Optional[int]
Version ID of the project.
- version_num : Optional[int]
Version number of the project. This argument can only be used in conjunction with the project.
- task_id : Optional[int]
Task ID. If not specified, the task ID will be determined automatically.
- meta : Optional[Union[WorkflowMeta, dict]]
Additional data for node customization.
- Returns
Response from the API.
- Return type
-
add_input_task(input_task_id, task_id=
None, meta=None)[source]¶ Add input type “task” to the workflow node. This type usually indicates that the one application has used another application for its work.
-
add_output_app(task_id=
None, meta=None)[source]¶ Add output type “app_session” to the workflow node. This type is used to show that the application has an offline session in which you can find the result of its work.
-
add_output_dataset(dataset, task_id=
None, meta=None)[source]¶ Add output type “dataset” to the workflow node. This type is used to show that the application has created a dataset with the result of its work. Customization of the dataset node is not supported and will be ignored. You can only customize the main node with this method.
- Parameters
- Returns
Response from the API.
- Return type
-
add_output_file(file, model_weight=
False, task_id=None, meta=None)[source]¶ Add output type “file” to the workflow node. This type is used to show that the application has created a file with the result of its work.
- Parameters
- Returns
Response from the API.
- Return type
-
add_output_folder(path, task_id=
None, meta=None)[source]¶ Add output type “folder” to the workflow node. Path to the folder is a path in Team Files. This type is used to show that the application has created a folder with the result files of its work.
-
add_output_job(id, task_id=
None, meta=None)[source]¶ Add output type “job” to the workflow node. Job is a Labeling Job. This type is used to show that the application has created a labeling job with the result of its work.
-
add_output_project(project, version_id=
None, task_id=None, meta=None)[source]¶ Add output type “project” to the workflow node. The project version can be specified with “version” argument to indicate that the project version was created especially as result of this task. This type is used to show that the application has created a project with the result of its work. Customization of the project node is not supported and will be ignored. You can only customize the main node with this method.
- Parameters
- Returns
Response from the API.
- Return type
-
add_output_task(output_task_id, task_id=
None, meta=None)[source]¶ Add output type “task” to the workflow node. This type is used to show that the application has created a task with the result of its work.
-
deploy_custom_model(workspace_id, artifacts_dir, checkpoint_name=
None, agent_id=None, device='cuda')¶ Deploy a custom model based on the artifacts directory.
- Parameters
- Raises
ValueError – if validations fail.
- Return type
-
download_git_archive(ecosystem_item_id, app_id, version, save_path, log_progress=
True, ext_logger=None)[source]¶
- get_context(id)¶
Get context information by task ID.
- Parameters
- id : int
Task ID in Supervisely.
- Returns
Context information in dict format
- Return type
- Usage example
import supervisely as sly task_id = 121230 os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() context = api.task.get_context(task_id) print(context) # Output: { # "team": { # "id": 16087, # "name": "alexxx" # }, # "workspace": { # "id": 23821, # "name": "my_super_workspace" # } # }
- get_ecosystem_module_id(slug)[source]¶
Returns ecosystem module id by slug. E.g. slug = “supervisely-ecosystem/export-to-supervisely-format”. Slug can be obtained from the application URL in browser.
- Parameters
- slug : str
module slug, starts with “supervisely-ecosystem/”
- Returns
ID of the module
- Return type
- Raises
- 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 load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() slug = "supervisely-ecosystem/export-to-supervisely-format" module_id = api.app.get_ecosystem_module_id(slug) print(f"Module {slug} has id {module_id}") # Module supervisely-ecosystem/export-to-supervisely-format has id 81
-
get_ecosystem_module_info(module_id, version=
None)[source]¶ Returns ModuleInfo object by module id and version.
- Parameters
- Returns
ModuleInfo object
- Return type
ModuleInfo
- 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 load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() module_id = 81 module_info = api.app.get_ecosystem_module_info(module_id)
- get_field(task_id, field)¶
- get_fields(task_id, fields)¶
- get_info_by_id(id)[source]¶
- Parameters
- id :
int int
- id :
- Return type
AppInfo- Returns
application info by numeric id
-
get_list(team_id, filter=
None, context=None, repository_key=None, show_disabled=False, integrated_into=None, session_tags=None, only_running=False, with_shared=True, force_all_sessions=True)[source]¶ Get list of applications for the specified team.
- Parameters
- team_id : int
team id
- filter : Optional[List[dict]]
list of filters
- context : Optional[List[str]]
list of application contexts
- repository_key : Optional[str]
repository key
- show_disabled : bool
show disabled applications
- integrated_into : Optional[List[str]]
destination of the application. Available values: “panel”, “files”, “standalone”, “data_commander”,
”image_annotation_tool”, “video_annotation_tool”, “dicom_annotation_tool”, “pointcloud_annotation_tool”
- session_tags : Optional[List[str]]
list of session tags
- only_running : bool
show only running applications (status is one of “queued”/”consumed”/”started”/”deployed”)
- with_shared : bool
include shared applications
- force_all_sessions : bool
force to get all sessions (tasks) for each application. Works only if only_running is False. Note that it can be a long operation.
- Returns
list of applications
- Return type
List[AppInfo]
- 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() team_id = 447 # Get list of all applications (including all tasks in `tasks` field) apps = api.app.get_list(team_id=team_id) # Get list of all applications (only running tasks included in `tasks` field) apps = api.app.get_list(team_id=team_id, force_all_sessions=False) # Get list of only running applications apps = api.app.get_list(team_id=team_id, only_running=True) # Get list of applications with specific filters filter = [{"field": "moduleId", "operator": "=", "value": 428}] apps = api.app.get_list(team_id=team_id, filter=filter)
-
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))
-
get_sessions(team_id, module_id, show_disabled=
False, session_name=None, statuses=None, with_shared=False)[source]¶ Get list of sessions (tasks) for the specified team and module.
- Parameters
- Returns
list of sessions
- Return type
List[SessionInfo]
- 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() team_id = 447 module_id = 428 # Get list of all sessions for the specified team and module ID sessions = api.app.get_sessions(team_id, module_id) # Get list of sessions with specific statuses from supervisely.api.task_api import TaskApi statuses = [TaskApi.Status.STARTED] sessions = api.app.get_sessions(team_id, module_id, statuses=statuses)
- is_ready_for_api_calls(task_id)[source]¶
Checks if app is ready for API calls. :type task_id:
int:param task_id: ID of the running task. :type task_id: int :rtype:bool:return: True if app is ready for API calls, False otherwise.
- list_checkpoints(task_id)¶
- raise_for_status(status)¶
Raise error if Task status is ERROR.
- Parameters
- status : Status
Status object.
- Returns
None
- Return type
NoneType
-
run_inference(agent_id, input_project_id, input_model_id, result_project_name, inference_config=
None)[source]¶
-
send_request(task_id, method, data, context=
{}, skip_response=False, timeout=60, outside_request=True, retries=10, raise_error=False)¶
- set_output_directory(task_id, file_id, directory_path)¶
-
set_output_error(task_id, title, description=
None, show_logs=True)¶ Set custom error message to the task output.
- Parameters
- Returns
Response JSON.
- Return type
Dict
- 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() task_id = 12345 title = "Something went wrong" description = "Please check the task logs" show_logs = True api.task.set_output_error(task_id, title, description, show_logs)
- set_output_experiment(task_id, experiment_info)¶
Sets output for the task with experiment info.
- Parameters
- Returns
None
- Return type
NoneType
Example of experiment_info:
- experiment_info = {
‘experiment_name’: ‘247_Lemons_RT-DETRv2-M’, ‘framework_name’: ‘RT-DETRv2’, ‘model_name’: ‘RT-DETRv2-M’, ‘task_type’: ‘object detection’, ‘project_id’: 76, ‘task_id’: 247, ‘model_files’: {‘config’: ‘model_config.yml’}, ‘checkpoints’: [‘checkpoints/best.pth’, ‘checkpoints/checkpoint0025.pth’, ‘checkpoints/checkpoint0050.pth’, ‘checkpoints/last.pth’], ‘best_checkpoint’: ‘best.pth’, ‘export’: {‘ONNXRuntime’: ‘export/best.onnx’}, ‘app_state’: ‘app_state.json’, ‘model_meta’: ‘model_meta.json’, ‘train_val_split’: ‘train_val_split.json’, ‘train_size’: 4, ‘val_size’: 2, ‘hyperparameters’: ‘hyperparameters.yaml’, ‘hyperparameters_id’: 45234, ‘artifacts_dir’: ‘/experiments/76_Lemons/247_RT-DETRv2/’, ‘datetime’: ‘2025-01-22 18:13:43’, ‘evaluation_report_id’: 12961, ‘evaluation_report_link’: ‘https://app.supervisely.com/model-benchmark?id=12961’, ‘evaluation_metrics’: {
‘mAP’: 0.994059405940594, ‘AP50’: 1.0, ‘AP75’: 1.0, ‘f1’: 0.9944444444444445, ‘precision’: 0.9944444444444445, ‘recall’: 0.9944444444444445, ‘iou’: 0.9726227736959404, ‘classification_accuracy’: 1.0, ‘calibration_score’: 0.8935745942476048, ‘f1_optimal_conf’: 0.500377893447876, ‘expected_calibration_error’: 0.10642540575239527, ‘maximum_calibration_error’: 0.499622106552124
}, ‘primary_metric’: ‘mAP’ ‘logs’: {
‘type’: ‘tensorboard’, ‘link’: ‘/experiments/76_Lemons/247_RT-DETRv2/logs/’
},
}
-
set_output_file_download(task_id, file_id, file_name, file_url=
None, download=True)¶ - Return type
-
set_output_text(task_id, title, description=
None, show_logs=False, zmdi_icon='zmdi-comment-alt-text', icon_color='#33c94c', background_color='#d9f7e4')¶ Set custom text message to the task output.
- Parameters
- task_id : int
Application task ID.
- title : str
Text message to be displayed in the task output.
- description : Optional[str]
Description to be displayed in the task output.
- show_logs : Optional[bool], default False
If True, the link to the task logs will be displayed in the task output.
- zmdi_icon : Optional[str], default "zmdi-comment-alt-text"
Icon class name from Material Design Icons (ZMDI).
- icon_color : Optional[str], default "#33c94c" (nearest Duron Jolly Green)
Icon color in HEX format.
- background_color : Optional[str], default "#d9f7e4" (Cosmic Latte)
Background color in HEX format.
- Returns
Response JSON.
- Return type
Dict
- 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() task_id = 12345 title = "Task is finished" api.task.set_output_text(task_id, title)
-
update_meta(id, data, agent_storage_folder=
None, relative_app_dir=None)¶ Update given task metadata :type id:
int:param id: int — task id :type data:dict:param data: dict — meta data to update
- update_status(task_id, status)¶
Sets the specified status for the task.
- Parameters
- Raises
ValueError – If the status value is not allowed.
- Return type
-
upload_dtl_archive(task_id, archive_path, progress_cb=
None)¶