Skip to content

Commit 251c3b9

Browse files
authored
Merge pull request #738 from superannotateai/item_category
added include categories option in list_items
2 parents e6425fd + 4ce8082 commit 251c3b9

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2977,7 +2977,7 @@ def list_items(
29772977
project: Union[NotEmptyStr, int],
29782978
folder: Optional[Union[NotEmptyStr, int]] = None,
29792979
*,
2980-
include: List[Literal["custom_metadata", "category"]] = None,
2980+
include: List[Literal["custom_metadata", "categories"]] = None,
29812981
**filters,
29822982
):
29832983
"""
@@ -2997,6 +2997,7 @@ def list_items(
29972997
Possible values are
29982998
29992999
- "custom_metadata": Includes custom metadata attached to the item.
3000+
- "categories": Includes categories attached to the item.
30003001
:type include: list of str, optional
30013002
30023003
:param filters: Specifies filtering criteria (e.g., name, ID, annotation status),
@@ -3067,6 +3068,40 @@ def list_items(
30673068
}
30683069
]
30693070
3071+
Request Example with include categories:
3072+
::
3073+
3074+
client.list_items(
3075+
project="My Multimodal",
3076+
folder="folder1",
3077+
include=["categories"]
3078+
)
3079+
3080+
Response Example:
3081+
::
3082+
3083+
[
3084+
{
3085+
"id": 48909383,
3086+
"name": "scan_123.jpeg",
3087+
"path": "Medical Annotations/folder1",
3088+
"url": "https://sa-public-files.s3.../scan_123.jpeg",
3089+
"annotation_status": "InProgress",
3090+
"createdAt": "2022-02-10T14:32:21.000Z",
3091+
"updatedAt": "2022-02-15T20:46:44.000Z",
3092+
"entropy_value": None,
3093+
"assignments": [],
3094+
"categories": [
3095+
{
3096+
"createdAt": "2025-01-29T13:51:39.000Z",
3097+
"updatedAt": "2025-01-29T13:51:39.000Z",
3098+
"id": 328577,
3099+
"name": "my_category",
3100+
},
3101+
],
3102+
}
3103+
]
3104+
30703105
Additional Filter Examples:
30713106
::
30723107
@@ -3088,6 +3123,14 @@ def list_items(
30883123
if isinstance(project, int)
30893124
else self.controller.get_project(project)
30903125
)
3126+
if (
3127+
include
3128+
and "categories" in include
3129+
and project.type != ProjectType.MULTIMODAL.value
3130+
):
3131+
raise AppException(
3132+
"The 'categories' option in the 'include' field is only supported for Multimodal projects."
3133+
)
30913134
if folder is None:
30923135
folder = self.controller.get_folder(project, "root")
30933136
else:

src/superannotate/lib/core/entities/items.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from lib.core.entities.base import BaseItemEntity
4+
from lib.core.entities.base import TimedBaseModel
45
from lib.core.enums import ApprovalStatus
56
from lib.core.enums import ProjectType
67
from lib.core.pydantic_v1 import Extra
@@ -16,6 +17,21 @@ class Config:
1617
extra = Extra.ignore
1718

1819

20+
class MultiModalItemCategoryEntity(TimedBaseModel):
21+
id: int = Field(None, alias="category_id")
22+
name: str = Field(None, alias="category_name")
23+
24+
class Config:
25+
extra = Extra.ignore
26+
27+
28+
class MultiModalItemEntity(BaseItemEntity):
29+
categories: Optional[list[MultiModalItemCategoryEntity]]
30+
31+
class Config:
32+
extra = Extra.ignore
33+
34+
1935
class VideoEntity(BaseItemEntity):
2036
approval_status: Optional[ApprovalStatus] = Field(None)
2137

@@ -51,4 +67,5 @@ class Config:
5167
ProjectType.TILED: ImageEntity,
5268
ProjectType.VIDEO: VideoEntity,
5369
ProjectType.DOCUMENT: DocumentEntity,
70+
ProjectType.MULTIMODAL: MultiModalItemEntity,
5471
}

src/superannotate/lib/core/usecases/items.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from lib.core.entities import ImageEntity
1818
from lib.core.entities import ProjectEntity
1919
from lib.core.entities import VideoEntity
20+
from lib.core.entities.items import MultiModalItemEntity
2021
from lib.core.exceptions import AppException
2122
from lib.core.exceptions import AppValidationException
2223
from lib.core.exceptions import BackendError
@@ -60,6 +61,8 @@ def serialize_item_entity(
6061
return VideoEntity(**entity.dict(by_alias=True))
6162
elif project.type == constants.ProjectType.DOCUMENT.value:
6263
return DocumentEntity(**entity.dict(by_alias=True))
64+
elif project.type == constants.ProjectType.MULTIMODAL.value:
65+
return MultiModalItemEntity(**entity.dict(by_alias=True))
6366
return entity
6467

6568

0 commit comments

Comments
 (0)