TaskApi¶
- class TaskApi[source]¶
Bases:
supervisely.api.module_api.ModuleApiBase
,supervisely.api.module_api.ModuleWithStatus
API for working with Tasks.
TaskApi
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.supervise.ly", token="4r47N...xaTatb") task_id = 121230 task_info = api.task.get_info_by_id(task_id)
Methods
- rtype
- rtype
- rtype
Get context information by task ID.
- rtype
Get Task information by ID.
List of Tasks in the given Workspace.
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
Check status of Task by ID.
Get list of all class field names.
Get string name of NamedTuple.
Raise error if Task status is ERROR.
- rtype
- rtype
- rtype
- rtype
- rtype
- rtype
- rtype
- rtype
Update given task metadata :type id:
int
:param id: int — task id :type data:dict
:param data: dict — meta data to update- rtype
Awaiting achievement by given Task of a given status.
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.
- class PluginTaskType[source]¶
Bases:
supervisely.collection.str_enum.StrEnum
PluginTaskType
-
CUSTOM =
'custom'
¶
-
INFERENCE =
'inference'
¶
-
INFERENCE_RPC =
'inference_rpc'
¶
-
SMART_TOOL =
'smarttool'
¶
-
TRAIN =
'train'
¶
-
CUSTOM =
- class RestartPolicy[source]¶
Bases:
supervisely.collection.str_enum.StrEnum
RestartPolicy
-
NEVER =
'never'
¶
-
ON_ERROR =
'on_error'
¶
-
NEVER =
- class Status[source]¶
Bases:
supervisely.collection.str_enum.StrEnum
Status
-
CONSUMED =
'consumed'
¶
-
DEPLOYED =
'deployed'
¶
-
ERROR =
'error'
¶
-
FINISHED =
'finished'
¶
-
QUEUED =
'queued'
¶
-
STARTED =
'started'
¶
-
STOPPED =
'stopped'
¶
-
TERMINATING =
'terminating'
¶
-
CONSUMED =
- get_context(id)[source]¶
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.supervise.ly' 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_info_by_id(id)[source]¶
Get Task information by ID.
- Parameters
- id : int
Task ID in Supervisely.
- Returns
Information about Task.
- Return type
NamedTuple
- Usage example
import supervisely as sly task_id = 121230 os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() task_info = api.task.get_info_by_id(task_id) print(task_info) # Output: { # "id": 121230, # "workspaceId": 23821, # "description": "", # "type": "clone", # "status": "finished", # "startedAt": "2019-12-19T12:13:09.702Z", # "finishedAt": "2019-12-19T12:13:09.701Z", # "userId": 16154, # "meta": { # "input": { # "model": { # "id": 1849 # }, # "isExternal": true, # "pluginVersionId": 84479 # }, # "output": { # "model": { # "id": 12380 # }, # "pluginVersionId": 84479 # } # }, # "settings": {}, # "agentName": null, # "userLogin": "alexxx", # "teamId": 16087, # "agentId": null # }
-
get_list(workspace_id, filters=
None
)[source]¶ List of Tasks in the given Workspace.
- Parameters
- Returns
List of Tasks with information for the given Workspace.
- Return type
List[NamedTuple]
- Usage example
import supervisely as sly workspace_id = 23821 os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() task_infos = api.task.get_list(workspace_id) task_infos_filter = api.task.get_list(23821, filters=[{'field': 'id', 'operator': '=', 'value': 121230}]) print(task_infos_filter) # Output: [ # { # "id": 121230, # "type": "clone", # "status": "finished", # "startedAt": "2019-12-19T12:13:09.702Z", # "finishedAt": "2019-12-19T12:13:09.701Z", # "meta": { # "input": { # "model": { # "id": 1849 # }, # "isExternal": true, # "pluginVersionId": 84479 # }, # "output": { # "model": { # "id": 12380 # }, # "pluginVersionId": 84479 # } # }, # "description": "" # } # ]
-
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
- get_status(task_id)[source]¶
Check status of Task by ID.
- Parameters
- id : int
Task ID in Supervisely.
- Returns
Status object
- Return type
- Usage example
import supervisely as sly task_id = 121230 os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() task_status = api.task.get_status(task_id) print(task_status) # Output: finished
- static info_sequence()¶
Get list of all class field names.
- static info_tuple_name()¶
Get string name of NamedTuple.
- raise_for_status(status)[source]¶
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
)[source]¶
-
set_output_file_download(task_id, file_id, file_name, file_url=
None
, download=True
)[source]¶ - Return type
-
start(agent_id, app_id=
None
, workspace_id=None
, description='application description'
, params=None
, log_level='info'
, users_ids=None
, app_version=''
, is_branch=False
, task_name='pythonSpawned'
, restart_policy='never'
, proxy_keep_url=False
, module_id=None
, redirect_requests={}
)[source]¶
-
update_meta(id, data, agent_storage_folder=
None
, relative_app_dir=None
)[source]¶ Update given task metadata :type id:
int
:param id: int — task id :type data:dict
:param data: dict — meta data to update
-
wait(id, target_status, wait_attempts=
None
, wait_attempt_timeout_sec=None
)[source]¶ Awaiting achievement by given Task of a given status.
- Parameters
- id : int
Task ID in Supervisely.
- target_status : Status
Status object(status of task we expect to destinate).
- wait_attempts : int, optional
The number of attempts to determine the status of the task that we are waiting for.
- wait_attempt_timeout_sec : int, optional
Number of seconds for intervals between attempts(raise error if waiting time exceeded).
- Returns
True if the desired status is reached, False otherwise
- Return type