Skip to content

Commit 15e5849

Browse files
fix: PLT-1018: Update sdk (#760)
Co-authored-by: fern-api[bot] <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: robot-ci-heartex <robot-ci-heartex@users.noreply.github.com>
1 parent 62fc44e commit 15e5849

8 files changed

Lines changed: 373 additions & 106 deletions

File tree

poetry.lock

Lines changed: 95 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reference.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,66 @@ Action which was performed in the last annotation history item
11321132
</dl>
11331133

11341134

1135+
</dd>
1136+
</dl>
1137+
</details>
1138+
1139+
<details><summary><code>client.annotations.<a href="src/label_studio_sdk/annotations/client.py">delete_bulk</a>() -&gt; AsyncHttpResponse[DeleteBulkAnnotationsResponse]</code></summary>
1140+
<dl>
1141+
<dd>
1142+
1143+
#### 📝 Description
1144+
1145+
<dl>
1146+
<dd>
1147+
1148+
<dl>
1149+
<dd>
1150+
1151+
Delete multiple annotations by their IDs. The deletion is processed synchronously. Returns the count of deleted annotations in the response.
1152+
</dd>
1153+
</dl>
1154+
</dd>
1155+
</dl>
1156+
1157+
#### 🔌 Usage
1158+
1159+
<dl>
1160+
<dd>
1161+
1162+
<dl>
1163+
<dd>
1164+
1165+
```python
1166+
from label_studio_sdk import LabelStudio
1167+
1168+
client = LabelStudio(
1169+
api_key="YOUR_API_KEY",
1170+
)
1171+
client.annotations.delete_bulk()
1172+
1173+
```
1174+
</dd>
1175+
</dl>
1176+
</dd>
1177+
</dl>
1178+
1179+
#### ⚙️ Parameters
1180+
1181+
<dl>
1182+
<dd>
1183+
1184+
<dl>
1185+
<dd>
1186+
1187+
**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.
1188+
1189+
</dd>
1190+
</dl>
1191+
</dd>
1192+
</dl>
1193+
1194+
11351195
</dd>
11361196
</dl>
11371197
</details>

src/label_studio_sdk/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274
)
275275
from .activity_logs import ListActivityLogsRequestMethod
276276
from .annotation_history import DeleteAnnotationHistoryResponse
277-
from .annotations import CreateBulkAnnotationsResponseItem
277+
from .annotations import CreateBulkAnnotationsResponseItem, DeleteBulkAnnotationsResponse
278278
from .client import AsyncLabelStudio, LabelStudio
279279
from .environment import LabelStudioEnvironment
280280
from .export_storage import ListTypesExportStorageResponseItem
@@ -394,6 +394,7 @@
394394
"Default165Enum": ".types",
395395
"DefaultRole": ".types",
396396
"DeleteAnnotationHistoryResponse": ".annotation_history",
397+
"DeleteBulkAnnotationsResponse": ".annotations",
397398
"DuplicateProjectsResponse": ".projects",
398399
"EditionEnum": ".types",
399400
"Export": ".types",
@@ -729,6 +730,7 @@ def __dir__():
729730
"Default165Enum",
730731
"DefaultRole",
731732
"DeleteAnnotationHistoryResponse",
733+
"DeleteBulkAnnotationsResponse",
732734
"DuplicateProjectsResponse",
733735
"EditionEnum",
734736
"Export",

src/label_studio_sdk/annotations/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
from importlib import import_module
77

88
if typing.TYPE_CHECKING:
9-
from .types import CreateBulkAnnotationsResponseItem
10-
_dynamic_imports: typing.Dict[str, str] = {"CreateBulkAnnotationsResponseItem": ".types"}
9+
from .types import CreateBulkAnnotationsResponseItem, DeleteBulkAnnotationsResponse
10+
_dynamic_imports: typing.Dict[str, str] = {
11+
"CreateBulkAnnotationsResponseItem": ".types",
12+
"DeleteBulkAnnotationsResponse": ".types",
13+
}
1114

1215

1316
def __getattr__(attr_name: str) -> typing.Any:
@@ -31,4 +34,4 @@ def __dir__():
3134
return sorted(lazy_attrs)
3235

3336

34-
__all__ = ["CreateBulkAnnotationsResponseItem"]
37+
__all__ = ["CreateBulkAnnotationsResponseItem", "DeleteBulkAnnotationsResponse"]

src/label_studio_sdk/annotations/client.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ..types.selected_items_request import SelectedItemsRequest
1111
from .raw_client import AsyncRawAnnotationsClient, RawAnnotationsClient
1212
from .types.create_bulk_annotations_response_item import CreateBulkAnnotationsResponseItem
13+
from .types.delete_bulk_annotations_response import DeleteBulkAnnotationsResponse
1314

1415
# this is used as the default value for optional parameters
1516
OMIT = typing.cast(typing.Any, ...)
@@ -159,6 +160,32 @@ def create_bulk(
159160
)
160161
return _response.data
161162

163+
def delete_bulk(self, *, request_options: typing.Optional[RequestOptions] = None) -> DeleteBulkAnnotationsResponse:
164+
"""
165+
Delete multiple annotations by their IDs. The deletion is processed synchronously. Returns the count of deleted annotations in the response.
166+
167+
Parameters
168+
----------
169+
request_options : typing.Optional[RequestOptions]
170+
Request-specific configuration.
171+
172+
Returns
173+
-------
174+
DeleteBulkAnnotationsResponse
175+
Annotations deleted successfully
176+
177+
Examples
178+
--------
179+
from label_studio_sdk import LabelStudio
180+
181+
client = LabelStudio(
182+
api_key="YOUR_API_KEY",
183+
)
184+
client.annotations.delete_bulk()
185+
"""
186+
_response = self._raw_client.delete_bulk(request_options=request_options)
187+
return _response.data
188+
162189
def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> Annotation:
163190
"""
164191
Retrieve a specific annotation for a task using the annotation result ID.
@@ -619,6 +646,42 @@ async def main() -> None:
619646
)
620647
return _response.data
621648

649+
async def delete_bulk(
650+
self, *, request_options: typing.Optional[RequestOptions] = None
651+
) -> DeleteBulkAnnotationsResponse:
652+
"""
653+
Delete multiple annotations by their IDs. The deletion is processed synchronously. Returns the count of deleted annotations in the response.
654+
655+
Parameters
656+
----------
657+
request_options : typing.Optional[RequestOptions]
658+
Request-specific configuration.
659+
660+
Returns
661+
-------
662+
DeleteBulkAnnotationsResponse
663+
Annotations deleted successfully
664+
665+
Examples
666+
--------
667+
import asyncio
668+
669+
from label_studio_sdk import AsyncLabelStudio
670+
671+
client = AsyncLabelStudio(
672+
api_key="YOUR_API_KEY",
673+
)
674+
675+
676+
async def main() -> None:
677+
await client.annotations.delete_bulk()
678+
679+
680+
asyncio.run(main())
681+
"""
682+
_response = await self._raw_client.delete_bulk(request_options=request_options)
683+
return _response.data
684+
622685
async def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> Annotation:
623686
"""
624687
Retrieve a specific annotation for a task using the annotation result ID.

src/label_studio_sdk/annotations/raw_client.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
from ..core.request_options import RequestOptions
1212
from ..core.serialization import convert_and_respect_annotation_metadata
1313
from ..core.unchecked_base_model import construct_type
14+
from ..errors.bad_request_error import BadRequestError
15+
from ..errors.forbidden_error import ForbiddenError
1416
from ..types.annotation import Annotation
1517
from ..types.last_action_enum import LastActionEnum
1618
from ..types.selected_items_request import SelectedItemsRequest
1719
from .types.create_bulk_annotations_response_item import CreateBulkAnnotationsResponseItem
20+
from .types.delete_bulk_annotations_response import DeleteBulkAnnotationsResponse
1821

1922
# this is used as the default value for optional parameters
2023
OMIT = typing.cast(typing.Any, ...)
@@ -167,6 +170,64 @@ def create_bulk(
167170
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
168171
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
169172

173+
def delete_bulk(
174+
self, *, request_options: typing.Optional[RequestOptions] = None
175+
) -> HttpResponse[DeleteBulkAnnotationsResponse]:
176+
"""
177+
Delete multiple annotations by their IDs. The deletion is processed synchronously. Returns the count of deleted annotations in the response.
178+
179+
Parameters
180+
----------
181+
request_options : typing.Optional[RequestOptions]
182+
Request-specific configuration.
183+
184+
Returns
185+
-------
186+
HttpResponse[DeleteBulkAnnotationsResponse]
187+
Annotations deleted successfully
188+
"""
189+
_response = self._client_wrapper.httpx_client.request(
190+
"api/annotations/bulk/",
191+
method="DELETE",
192+
request_options=request_options,
193+
)
194+
try:
195+
if 200 <= _response.status_code < 300:
196+
_data = typing.cast(
197+
DeleteBulkAnnotationsResponse,
198+
construct_type(
199+
type_=DeleteBulkAnnotationsResponse, # type: ignore
200+
object_=_response.json(),
201+
),
202+
)
203+
return HttpResponse(response=_response, data=_data)
204+
if _response.status_code == 400:
205+
raise BadRequestError(
206+
headers=dict(_response.headers),
207+
body=typing.cast(
208+
typing.Any,
209+
construct_type(
210+
type_=typing.Any, # type: ignore
211+
object_=_response.json(),
212+
),
213+
),
214+
)
215+
if _response.status_code == 403:
216+
raise ForbiddenError(
217+
headers=dict(_response.headers),
218+
body=typing.cast(
219+
typing.Any,
220+
construct_type(
221+
type_=typing.Any, # type: ignore
222+
object_=_response.json(),
223+
),
224+
),
225+
)
226+
_response_json = _response.json()
227+
except JSONDecodeError:
228+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
229+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
230+
170231
def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[Annotation]:
171232
"""
172233
Retrieve a specific annotation for a task using the annotation result ID.
@@ -614,6 +675,64 @@ async def create_bulk(
614675
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
615676
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
616677

678+
async def delete_bulk(
679+
self, *, request_options: typing.Optional[RequestOptions] = None
680+
) -> AsyncHttpResponse[DeleteBulkAnnotationsResponse]:
681+
"""
682+
Delete multiple annotations by their IDs. The deletion is processed synchronously. Returns the count of deleted annotations in the response.
683+
684+
Parameters
685+
----------
686+
request_options : typing.Optional[RequestOptions]
687+
Request-specific configuration.
688+
689+
Returns
690+
-------
691+
AsyncHttpResponse[DeleteBulkAnnotationsResponse]
692+
Annotations deleted successfully
693+
"""
694+
_response = await self._client_wrapper.httpx_client.request(
695+
"api/annotations/bulk/",
696+
method="DELETE",
697+
request_options=request_options,
698+
)
699+
try:
700+
if 200 <= _response.status_code < 300:
701+
_data = typing.cast(
702+
DeleteBulkAnnotationsResponse,
703+
construct_type(
704+
type_=DeleteBulkAnnotationsResponse, # type: ignore
705+
object_=_response.json(),
706+
),
707+
)
708+
return AsyncHttpResponse(response=_response, data=_data)
709+
if _response.status_code == 400:
710+
raise BadRequestError(
711+
headers=dict(_response.headers),
712+
body=typing.cast(
713+
typing.Any,
714+
construct_type(
715+
type_=typing.Any, # type: ignore
716+
object_=_response.json(),
717+
),
718+
),
719+
)
720+
if _response.status_code == 403:
721+
raise ForbiddenError(
722+
headers=dict(_response.headers),
723+
body=typing.cast(
724+
typing.Any,
725+
construct_type(
726+
type_=typing.Any, # type: ignore
727+
object_=_response.json(),
728+
),
729+
),
730+
)
731+
_response_json = _response.json()
732+
except JSONDecodeError:
733+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
734+
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
735+
617736
async def get(
618737
self, id: int, *, request_options: typing.Optional[RequestOptions] = None
619738
) -> AsyncHttpResponse[Annotation]:

src/label_studio_sdk/annotations/types/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
if typing.TYPE_CHECKING:
99
from .create_bulk_annotations_response_item import CreateBulkAnnotationsResponseItem
10+
from .delete_bulk_annotations_response import DeleteBulkAnnotationsResponse
1011
_dynamic_imports: typing.Dict[str, str] = {
11-
"CreateBulkAnnotationsResponseItem": ".create_bulk_annotations_response_item"
12+
"CreateBulkAnnotationsResponseItem": ".create_bulk_annotations_response_item",
13+
"DeleteBulkAnnotationsResponse": ".delete_bulk_annotations_response",
1214
}
1315

1416

@@ -33,4 +35,4 @@ def __dir__():
3335
return sorted(lazy_attrs)
3436

3537

36-
__all__ = ["CreateBulkAnnotationsResponseItem"]
38+
__all__ = ["CreateBulkAnnotationsResponseItem", "DeleteBulkAnnotationsResponse"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
import typing
4+
5+
import pydantic
6+
from ...core.pydantic_utilities import IS_PYDANTIC_V2
7+
from ...core.unchecked_base_model import UncheckedBaseModel
8+
9+
10+
class DeleteBulkAnnotationsResponse(UncheckedBaseModel):
11+
deleted_count: typing.Optional[int] = pydantic.Field(default=None)
12+
"""
13+
Number of annotations deleted
14+
"""
15+
16+
if IS_PYDANTIC_V2:
17+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
18+
else:
19+
20+
class Config:
21+
frozen = True
22+
smart_union = True
23+
extra = pydantic.Extra.allow

0 commit comments

Comments
 (0)