Project API

class supervisely_lib.api.project_api.ProjectApi(api)[source]

Bases: supervisely_lib.api.module_api.CloneableModuleApi, supervisely_lib.api.module_api.UpdateableModule, supervisely_lib.api.module_api.RemoveableModuleApi

API for working with Project. ProjectApi object is immutable.

Parameters

api (Api) – API connection to the server

Usage example
# You can connect to API directly
address = 'https://app.supervise.ly/'
token = 'Your Supervisely API Token'
api = sly.Api(address, token)

# Or you can use API from environment
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_id = 1951
project_info = api.project.get_info_by_id(project_id)
static info_sequence()[source]

NamedTuple ProjectInfo with API Fields containing information about Project.

Example
ProjectInfo(id=999,
            name='Cat_breeds',
            description='',
            size='861069',
            readme='',
            workspace_id=58,
            images_count=10,
            items_count=10,
            datasets_count=2,
            created_at='2020-11-17T17:44:28.158Z',
            updated_at='2021-03-01T10:51:57.545Z',
            type='images',
            reference_image_url='http://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/...jpg')
static info_tuple_name()[source]

NamedTuple name - ProjectInfo.

get_list(workspace_id: int, filters: Optional[List[dict]] = None) → List[NamedTuple][source]

List of Projects in the given Workspace.

Parameters
  • workspace_id (int) – Workspace ID in which the Projects are located.

  • filters (List[dict], optional) – List of params to sort output Projects.

Returns

List of all projects with information for the given Workspace. See info_sequence

Return type

List[NamedTuple]

Usage example
workspace_id = 58

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_list = api.project.get_list(workspace_id)
print(project_list)
# Output: [
# ProjectInfo(id=861,
#             name='Project_COCO',
#             description='',
#             size='22172241',
#             readme='',
#             workspace_id=58,
#             images_count=6,
#             items_count=6,
#             datasets_count=1,
#             created_at='2020-11-09T18:21:32.356Z',
#             updated_at='2020-11-09T18:21:32.356Z',
#             type='images',
#             reference_image_url='http://78.46.75.100:38585/h5un6l2bnaz1vj8a9qgms4-public/images/original/...jpg'),
# ProjectInfo(id=999,
#             name='Cat_breeds',
#             description='',
#             size='861069',
#             readme='',
#             workspace_id=58,
#             images_count=10,
#             items_count=10,
#             datasets_count=2,
#             created_at='2020-11-17T17:44:28.158Z',
#             updated_at='2021-03-01T10:51:57.545Z',
#             type='images',
#             reference_image_url='http://78.46.75.100:38585/h5un6l2bnaz1vj8a9qgms4-public/images/original/...jpg')
# ]

# Filtered Project list
project_list = api.project.get_list(workspace_id, filters=[{ 'field': 'name', 'operator': '=', 'value': 'Cat_breeds'}])
print(project_list)
# Output: ProjectInfo(id=999,
#                     name='Cat_breeds',
#                     description='',
#                     size='861069',
#                     readme='',
#                     workspace_id=58,
#                     images_count=10,
#                     items_count=10,
#                     datasets_count=2,
#                     created_at='2020-11-17T17:44:28.158Z',
#                     updated_at='2021-03-01T10:51:57.545Z',
#                     type='images',
#                     reference_image_url='http://78.46.75.100:38585/h5un6l2bnaz1vj8a9qgms4-public/images/original/...jpg')
# ]
get_info_by_id(id: int, expected_type: Optional[str] = None, raise_error: bool = False) → NamedTuple[source]

Get Project information by ID.

Parameters
  • id (int) – Project ID in Supervisely.

  • expected_type (ProjectType, optional) – Expected ProjectType.

  • raise_error (bool, optional) – If True raise error if given name is missing in the Project, otherwise skips missing names.

Raises

Error if type of project is not None and != expected type

Returns

Information about Project. See info_sequence

Return type

NamedTuple

Usage example
project_id = 1951

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_info = api.project.get_info_by_id(project_id)
print(project_info)
# Output: ProjectInfo(id=861,
#                     name='fruits_annotated',
#                     description='',
#                     size='22172241',
#                     readme='',
#                     workspace_id=58,
#                     images_count=6,
#                     items_count=6,
#                     datasets_count=1,
#                     created_at='2020-11-09T18:21:32.356Z',
#                     updated_at='2020-11-09T18:21:32.356Z',
#                     type='images',
#                     reference_image_url='http://78.46.75.100:38585/h5un6l2bnaz1vj8a9qgms4-public/images/original/...jpg')
get_info_by_name(parent_id: int, name: str, expected_type: Optional[supervisely_lib.project.project_type.ProjectType] = None, raise_error: bool = False) → NamedTuple[source]

Get Project information by name.

Parameters
  • parent_id (int) – Workspace ID.

  • name (str) – Project name.

  • expected_type (ProjectType, optional) – Expected ProjectType.

  • raise_error (bool, optional) – If True raise error if given name is missing in the Project, otherwise skips missing names.

Returns

Information about Project. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_info = api.project.get_info_by_name(58, "fruits_annotated")
print(project_info)
# Output: ProjectInfo(id=861,
#                     name='fruits_annotated',
#                     description='',
#                     size='22172241',
#                     readme='',
#                     workspace_id=58,
#                     images_count=6,
#                     items_count=6,
#                     datasets_count=1,
#                     created_at='2020-11-09T18:21:32.356Z',
#                     updated_at='2020-11-09T18:21:32.356Z',
#                     type='images',
#                     reference_image_url='http://78.46.75.100:38585/h5un6l2bnaz1vj8a9qgms4-public/images/original/...jpg')
get_meta(id: int) → dict[source]

Get ProjectMeta by Project ID.

Parameters

id (int) – Project ID in Supervisely.

Returns

ProjectMeta dict

Return type

dict

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_meta = api.project.get_meta(project_id)
print(project_meta)
# Output: {
#     "classes":[
#         {
#             "id":22310,
#             "title":"kiwi",
#             "shape":"bitmap",
#             "hotkey":"",
#             "color":"#FF0000"
#         },
#         {
#             "id":22309,
#             "title":"lemon",
#             "shape":"bitmap",
#             "hotkey":"",
#             "color":"#51C6AA"
#         }
#     ],
#     "tags":[],
#     "projectType":"images"
# }
create(workspace_id: int, name: str, type: supervisely_lib.project.project_type.ProjectType = <ProjectType.IMAGES: 'images'>, description: str = '', change_name_if_conflict: bool = False) → NamedTuple[source]

Create Project with given name in the given Workspace ID.

Parameters
  • workspace_id (int) – Workspace ID in Supervisely where Project will be created.

  • name (str) – Project Name.

  • type (ProjectType) – Type of created Project.

  • description (str) – Project description.

  • change_name_if_conflict (bool, optional) – Checks if given name already exists and adds suffix to the end of the name.

Returns

Information about Project. See info_sequence

Return type

NamedTuple

Usage example
workspace_id = 8

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

new_proj = api.project.create(workspace_id, "fruits_test", sly.ProjectType.IMAGES)
print(new_proj)
# Output: ProjectInfo(id=1993,
#                     name='fruits_test',
#                     description='',
#                     size='0',
#                     readme='',
#                     workspace_id=58,
#                     images_count=None,
#                     items_count=None,
#                     datasets_count=None,
#                     created_at='2021-03-11T09:28:42.585Z',
#                     updated_at='2021-03-11T09:28:42.585Z',
#                     type='images',
#                     reference_image_url=None)
update_meta(id: int, meta: dict) → None[source]

Updates given Project with given ProjectMeta.

Parameters
  • id (int) – Project ID in Supervisely.

  • meta (dict) – ProjectMeta dict

Returns

None

Return type

NoneType

Usage example
lemons_proj_id = 1951
kiwis_proj_id = 1952

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_meta = api.project.get_meta(lemons_proj_id)
updated_meta = api.project.update_meta(kiwis_proj_id, project_meta)
get_datasets_count(id: int) → int[source]

Number of Datasets in the given Project by ID.

Parameters

id (int) – Project ID in Supervisely.

Returns

Number of Datasets in the given Project

Return type

int

Usage example
project_id = 454

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_ds_count = api.project.get_datasets_count(project_id)
print(project_ds_count)
# Output: 4
get_images_count(id: int) → int[source]

Number of images in the given Project by ID.

Parameters

id (int) – Project ID in Supervisely.

Returns

Number of images in the given Project

Return type

int

Usage example
project_id = 454

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_imgs_count = api.project.get_images_count(project_id)
print(project_imgs_count)
# Output: 24
merge_metas(src_project_id: int, dst_project_id: int) → dict[source]

Merges ProjectMeta from given Project to given destination Project.

Parameters
  • src_project_id (int) – Source Project ID.

  • dst_project_id (int) – Destination Project ID.

Returns

ProjectMeta dict

Return type

dict

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

lemons_proj_id = 1951
kiwis_proj_id = 1980

merged_projects = api.project.merge_metas(lemons_proj_id, kiwis_proj_id)
get_activity(id: int) → pandas.core.frame.DataFrame[source]

Get Project activity by ID.

Parameters

id (int) – Project ID in Supervisely.

Returns

Pandas DataFrame

Return type

DataFrame

Usage example
project_id = 1951

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_activity = api.project.get_activity(project_id)
print(project_activity)
# Output:    userId               action  ... tagId             meta
#         0       7  annotation_duration  ...  None  {'duration': 1}
#         1       7  annotation_duration  ...  None  {'duration': 2}
#         2       7        create_figure  ...  None               {}
#
#         [3 rows x 18 columns]
get_stats(id: int) → dict[source]

Get Project stats by ID.

Parameters

id (int) – Project ID in Supervisely.

Returns

Project statistics

Return type

dict

Usage example
project_id = 1951

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_stats = api.project.get_stats(project_id)
url(id: int) → str[source]

Get Project URL by ID.

Parameters

id (int) – Project ID in Supervisely.

Returns

Project URL

Return type

str

Usage example
project_id = 1951

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

project_url = api.project.url(project_id)
print(project_url)
# Output: http://supervise.ly/projects/1951/datasets
update_custom_data(id: int, data: dict) → dict[source]

Updates custom data of the Project by ID

Parameters
  • id (int) – Project ID in Supervisely.

  • data (dict) – Custom data

Returns

Project information in dict format

Return type

dict

Usage example
project_id = 1951
custom_data = {1:2}

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

new_info = api.project.update_custom_data(project_id, custom_data)
InfoType

alias of supervisely_lib.api.module_api.ProjectInfo