Skip to content

Commit 03b2952

Browse files
authored
Merge pull request #503 from superannotateai/1304_add_items_to_subset
1304 add items to subset
2 parents 21eedd0 + df1ed32 commit 03b2952

File tree

6 files changed

+454
-1
lines changed

6 files changed

+454
-1
lines changed

docs/source/superannotate.sdk.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Subsets
9494
______
9595

9696
.. automethod:: superannotate.SAClient.get_subsets
97+
.. automethod:: superannotate.SAClient.add_items_to_subset
9798

9899
----------
99100

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,3 +3044,80 @@ def delete_custom_values(
30443044
)
30453045
if response.errors:
30463046
raise AppException(response.errors)
3047+
3048+
def add_items_to_subset(
3049+
self, project: NotEmptyStr, subset: NotEmptyStr, items: List[dict]
3050+
):
3051+
"""
3052+
3053+
Associates selected items with a given subset. Non-existing subset will be automatically created.
3054+
3055+
:param project: project name (e.g., “project1”)
3056+
:type project: str
3057+
3058+
:param subset: a name of an existing/new subset to associate items with. New subsets will be automatically created.
3059+
:type subset: str
3060+
3061+
:param items: list of items metadata. Required keys are 'name' and 'path'
3062+
:type items: list of dicts
3063+
3064+
Request Example:
3065+
::
3066+
client = SAClient()
3067+
3068+
# option 1
3069+
queried_items = client.query(
3070+
project="Image Project",
3071+
query="instance(error = true)"
3072+
)
3073+
3074+
client.add_items_to_subset(
3075+
project="Medical Annotations",
3076+
subset="Brain Study - Disapproved",
3077+
items=queried_items
3078+
)
3079+
3080+
items_list = [
3081+
{
3082+
'name': 'image_1.jpeg',
3083+
'path': 'Image Project'
3084+
},
3085+
{
3086+
'name': 'image_2.jpeg',
3087+
'path': 'Image Project/Subfolder A'
3088+
}
3089+
]
3090+
3091+
client.add_items_to_subset(
3092+
project="Image Project",
3093+
subset="Subset Name",
3094+
items=items_list
3095+
3096+
)
3097+
3098+
Response Example:
3099+
::
3100+
{
3101+
"succeeded": [
3102+
{
3103+
'name': 'image_1.jpeg',
3104+
'path': 'Image Project'
3105+
},
3106+
{
3107+
'name': 'image_2.jpeg',
3108+
'path': 'Image Project/Subfolder A'
3109+
}
3110+
],
3111+
"failed": [],
3112+
"skipped": []
3113+
}
3114+
"""
3115+
3116+
project_name, _ = extract_project_folder(project)
3117+
3118+
response = self.controller.add_items_to_subset(project_name, subset, items)
3119+
3120+
if response.errors:
3121+
raise AppException(response.errors)
3122+
3123+
return response.data

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class BaseItemEntity(TimedBaseModel):
264264
createdAt: str = Field(description="Date of creation")
265265
updatedAt: str = Field(description="Update date")
266266
custom_metadata: Optional[dict]
267+
id: Optional[int]
267268

268269
class Config:
269270
extra = Extra.allow

0 commit comments

Comments
 (0)