Dataset API

class supervisely_lib.api.dataset_api.DatasetApi(api)[source]

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

API for working with Dataset. DatasetApi 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
ds = api.dataset.get_list(project_id)
static info_sequence()[source]

NamedTuple DatasetInfo information about Dataset.

Example
DatasetInfo(id=452984,
            name='ds0',
            description='',
            size='3997776',
            project_id=118909,
            images_count=11,
            items_count=11,
            created_at='2021-03-03T15:54:08.802Z',
            updated_at='2021-03-16T09:31:37.063Z',
            reference_image_url='https://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/K/q/jf/...png')
static info_tuple_name()[source]

NamedTuple name - DatasetInfo.

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

List of Datasets in the given Project.

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

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

Returns

List of all Datasets with information for the given Project. See info_sequence

Return type

List[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()
ds = api.dataset.get_list(project_id)

print(ds)
# Output: [
#     DatasetInfo(id=2532,
#                 name="lemons",
#                 description="",
#                 size="861069",
#                 project_id=1951,
#                 images_count=6,
#                 items_count=6,
#                 created_at="2021-03-02T10:04:33.973Z",
#                 updated_at="2021-03-10T09:31:50.341Z",
#                 reference_image_url="http://app.supervise.ly/z6ut6j8bnaz1vj8aebbgs4-public/images/original/...jpg"),
#                 DatasetInfo(id=2557,
#                 name="kiwi",
#                 description="",
#                 size="861069",
#                 project_id=1951,
#                 images_count=6,
#                 items_count=6,
#                 created_at="2021-03-10T09:31:33.701Z",
#                 updated_at="2021-03-10T09:31:44.196Z",
#                 reference_image_url="http://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/...jpg")
# ]
get_info_by_id(id: int) → NamedTuple[source]

Get Datasets information by ID.

Parameters

id (int) – Dataset ID in Supervisely.

Returns

Information about Dataset. See info_sequence

Return type

NamedTuple

Usage example
dataset_id = 384126

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

ds_info = api.dataset.get_info_by_id(dataset_id)
create(project_id: int, name: str, description: str = '', change_name_if_conflict: bool = False) → NamedTuple[source]

Create Dataset with given name in the given Project.

Parameters
  • project_id (int) – Project ID in Supervisely where Dataset will be created.

  • name (str) – Dataset Name.

  • description (str, optional) – Dataset 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 Dataset. See info_sequence

Return type

NamedTuple

Usage example
project_id = 116482

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

ds_info = api.dataset.get_list(project_id)
print(len(ds_info)) # 1

new_ds = api.dataset.create(project_id, 'new_ds')
new_ds_info = api.dataset.get_list(project_id)
print(len(new_ds_info)) # 2
get_or_create(project_id: int, name: str, description: str = '') → NamedTuple[source]

Checks if Dataset with given name already exists in the Project, if not creates Dataset with the given name.

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

  • name (str) – Dataset name.

  • description (str, optional) – Dataset description.

Returns

Information about Dataset. See info_sequence

Return type

NamedTuple

Usage example
project_id = 116482

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

ds_info = api.dataset.get_list(project_id)
print(len(ds_info)) # 1

api.dataset.get_or_create(project_id, 'ds1')
ds_info = api.dataset.get_list(project_id)
print(len(ds_info)) # 1

api.dataset.get_or_create(project_id, 'new_ds')
ds_info = api.dataset.get_list(project_id)
print(len(ds_info)) # 2
copy_batch(dst_project_id: int, ids: List[int], new_names: Optional[List[str]] = None, change_name_if_conflict: bool = False, with_annotations: bool = False) → List[NamedTuple][source]

Copy given Datasets to the destination Project by IDs.

Parameters
  • dst_project_id (int) – Destination Project ID in Supervisely.

  • ids (List[int]) – IDs of copied Datasets.

  • new_names (List[str], optional) – New Datasets names.

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

  • with_annotations (bool, optional) – If True copies Datasets with annotations, otherwise copies just items from Datasets without annotations.

Raises

RuntimeError if can not match “ids” and “new_names” lists, len(ids) != len(new_names)

Returns

Information about Datasets. 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()

dst_proj_id = 1980
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 0

ds_ids = [2532, 2557]
ds_names = ["lemon_test", "kiwi_test"]

copied_datasets = api.dataset.copy_batch(dst_proj_id, ids=ds_ids, new_names=ds_names, with_annotations=True)
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 2
copy(dst_project_id: int, id: int, new_name: Optional[str] = None, change_name_if_conflict: bool = False, with_annotations: bool = False) → NamedTuple[source]

Copies given Dataset in destination Project by ID.

Parameters
  • dst_project_id (int) – Destination Project ID in Supervisely.

  • id (int) – ID of copied Dataset.

  • new_name (str, optional) – New Dataset name.

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

  • with_annotations (bool, optional) – If True copies Dataset with annotations, otherwise copies just items from Dataset without annotation.

Returns

Information about Dataset. 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()

dst_proj_id = 1982
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 0

new_ds = api.dataset.copy(dst_proj_id, id=2540, new_name="banana", with_annotations=True)
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 1
move_batch(dst_project_id: int, ids: List[int], new_names: Optional[List[str]] = None, change_name_if_conflict: bool = False, with_annotations: bool = False) → List[NamedTuple][source]

Moves given Datasets to the destination Project by IDs.

Parameters
  • dst_project_id (int) – Destination Project ID in Supervisely.

  • ids (List[int]) – IDs of moved Datasets.

  • new_names (List[str], optional) – New Datasets names.

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

  • with_annotations (bool, optional) – If True moves Datasets with annotations, otherwise moves just items from Datasets without annotations.

Raises

RuntimeError if can not match “ids” and “new_names” lists, len(ids) != len(new_names)

Returns

Information about Datasets. 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()

dst_proj_id = 1978
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 0

ds_ids = [2545, 2560]
ds_names = ["banana_test", "mango_test"]

movied_datasets = api.dataset.move_batch(dst_proj_id, ids=ds_ids, new_names=ds_names, with_annotations=True)
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 2
move(dst_project_id: int, id: int, new_name: Optional[str] = None, change_name_if_conflict: bool = False, with_annotations: bool = False) → NamedTuple[source]

Moves given Dataset in destination Project by ID.

Parameters
  • dst_project_id (int) – Destination Project ID in Supervisely.

  • id (int) – ID of moved Dataset.

  • new_name (str, optional) – New Dataset name.

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

  • with_annotations (bool, optional) – If True moves Dataset with annotations, otherwise moves just items from Dataset without annotation.

Returns

Information about Dataset. 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()

dst_proj_id = 1985
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 0

new_ds = api.dataset.move(dst_proj_id, id=2550, new_name="cucumber", with_annotations=True)
ds = api.dataset.get_list(dst_proj_id)
print(len(ds)) # 1
InfoType

alias of supervisely_lib.api.module_api.DatasetInfo