ObjClass API

class supervisely_lib.api.object_class_api.ObjectClassApi(api)[source]

Bases: supervisely_lib.api.module_api.ModuleApi

API for working with ObjClass. ObjectClassApi 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
obj_class_infos = api.object_class.get_list(project_id)
static info_sequence()[source]

NamedTuple ObjectClassInfo information about ObjectClass.

Example
ObjectClassInfo(id=22309,
                name='lemon',
                description='',
                shape='bitmap',
                color='#51C6AA',
                settings={},
                created_at='2021-03-02T10:04:33.973Z',
                updated_at='2021-03-11T09:37:07.111Z')
static info_tuple_name()[source]

NamedTuple name - ObjectClassInfo.

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

List of ObjClasses in the given Project.

Parameters
  • project_id (int) – Project ID in which the ObjClasses are located.

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

Returns

List of ObjClasses with information from the given Project. See info_sequence

Return type

List[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_id = 1951
obj_class_infos = api.object_class.get_list(project_id)
print(obj_class_infos)
# Output: [ObjectClassInfo(id=22309,
#                          name='lemon',
#                          description='',
#                          shape='bitmap',
#                          color='#51C6AA',
#                          settings={},
#                          created_at='2021-03-02T10:04:33.973Z',
#                          updated_at='2021-03-11T09:37:07.111Z'),
#  ObjectClassInfo(id=22310,
#                  name='kiwi',
#                  description='',
#                  shape='bitmap',
#                  color='#FF0000',
#                  settings={},
#                  created_at='2021-03-02T10:04:33.973Z',
#                  updated_at='2021-03-11T09:37:07.111Z')
# ]

obj_class_list = api.object_class.get_list(1951, filters=[{'field': 'name', 'operator': '=', 'value': 'lemon' }])
print(obj_class_list)
# Output: [
#     [
#         22309,
#         "lemon",
#         "",
#         "bitmap",
#         "#51C6AA",
#         {},
#         "2021-03-02T10:04:33.973Z",
#         "2021-03-11T09:37:07.111Z"
#     ]
# ]
get_name_to_id_map(project_id: int) → dict[source]
Parameters

project_id (int) – Project ID in which the ObjClasses are located.

Returns

Dictionary Key ID Map {‘key’: id}

Return type

KeyIdMap

Usage example

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

obj_class_map = api.object_class.get_name_to_id_map(1951)
print(obj_class_map)
# Output: {'lemon': 22309, 'kiwi': 22310, 'cucumber': 22379}
InfoType

alias of supervisely_lib.api.module_api.ObjectClassInfo