Skip to content

Commit 883a944

Browse files
committed
Update docs
1 parent 299c3c2 commit 883a944

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ History
77
All release highlights of this project will be documented in this file.
88

99
4.4.32 - March 4, 2025
10-
_____________________
10+
______________________
1111

1212
**Fixed**
1313

14-
- ``SAClient.item_context`` Fixed an issue where setting a component value would overwrite existing comments and other associated data.
14+
- ``SAClient.item_context`` Fixed an issue where setting a component value would overwrite existing comments and other associated data.
1515

1616
4.4.31 - Feb 27, 2025
1717
_____________________

docs/source/api_reference/api_item.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Items
99
.. automethod:: superannotate.SAClient.search_items
1010
.. automethod:: superannotate.SAClient.attach_items
1111
.. automethod:: superannotate.SAClient.item_context
12+
.. autoclass:: superannotate.ItemContext
13+
:members: get_metadata, get_component_value, set_component_value
14+
:member-order: bysource
15+
1216
.. automethod:: superannotate.SAClient.copy_items
1317
.. automethod:: superannotate.SAClient.move_items
1418
.. automethod:: superannotate.SAClient.delete_items

src/superannotate/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from superannotate.lib.app.input_converters import export_annotation
2222
from superannotate.lib.app.input_converters import import_annotation
2323
from superannotate.lib.app.interface.sdk_interface import SAClient
24+
from superannotate.lib.app.interface.sdk_interface import ItemContext
2425

2526

2627
SESSIONS = {}
@@ -29,6 +30,7 @@
2930
__all__ = [
3031
"__version__",
3132
"SAClient",
33+
"ItemContext",
3234
# Utils
3335
"enums",
3436
"AppException",

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ class Attachment(TypedDict, total=False):
118118

119119

120120
class ItemContext:
121+
"""
122+
A context manager for handling annotations and metadata of an item.
123+
124+
The ItemContext class provides methods to retrieve and manage metadata and component
125+
values for items in the specified context. Below are the descriptions and usage examples for each method.
126+
127+
Example:
128+
::
129+
130+
with sa_client.item_context("project_name/folder_name", "item_name") as context:
131+
metadata = context.get_metadata()
132+
print(metadata)
133+
"""
134+
121135
def __init__(
122136
self,
123137
controller: Controller,
@@ -171,9 +185,26 @@ def annotation(self):
171185
return self.annotation_adapter.annotation
172186

173187
def __enter__(self):
188+
"""
189+
Enters the context manager.
190+
191+
Returns:
192+
ItemContext: The instance itself.
193+
"""
174194
return self
175195

176196
def __exit__(self, exc_type, exc_val, exc_tb):
197+
"""
198+
Exits the context manager, saving changes if no exception occurred.
199+
200+
Args:
201+
exc_type (Optional[Type[BaseException]]): Exception type if raised.
202+
exc_val (Optional[BaseException]): Exception instance if raised.
203+
exc_tb (Optional[TracebackType]): Traceback if an exception occurred.
204+
205+
Returns:
206+
bool: True if no exception occurred, False otherwise.
207+
"""
177208
if exc_type:
178209
return False
179210

@@ -188,12 +219,62 @@ def save(self):
188219
self._annotation_adapter.save()
189220

190221
def get_metadata(self):
222+
"""
223+
Retrieves the metadata associated with the current item context.
224+
225+
:return: A dictionary containing metadata for the current item.
226+
:rtype: dict
227+
228+
Request Example:
229+
::
230+
231+
with client.item_context(("project_name", "folder_name"), 12345) as context:
232+
metadata = context.get_metadata()
233+
print(metadata)
234+
"""
191235
return self.annotation["metadata"]
192236

193237
def get_component_value(self, component_id: str):
238+
"""
239+
Retrieves the value of a specific component within the item context.
240+
241+
:param component_id: The name of the component whose value is to be retrieved.
242+
:type component_id: str
243+
244+
:return: The value of the specified component.
245+
:rtype: Any
246+
247+
Request Example:
248+
::
249+
250+
with client.item_context((101, 202), "item_name") as context: # (101, 202) project and folder IDs
251+
value = context.get_component_value("component_id")
252+
print(value)
253+
"""
194254
return self.annotation_adapter.get_component_value(component_id)
195255

196256
def set_component_value(self, component_id: str, value: Any):
257+
"""
258+
Updates the value of a specific component within the item context.
259+
260+
:param component_id: The component identifier.
261+
:type component_id: str
262+
263+
:param value: The new value to set for the specified component.
264+
:type value: Any
265+
266+
:return: The instance itself to allow method chaining.
267+
:rtype: ItemContext
268+
269+
Request Example:
270+
::
271+
272+
with client.item_context("project_name/folder_name", "item_name") as item_context:
273+
metadata = item_context.get_metadata()
274+
value = item_context.get_component_value("component_id")
275+
item_context.set_component_value("component_id", value)
276+
277+
"""
197278
self.annotation_adapter.set_component_value(component_id, value)
198279
return self
199280

@@ -381,6 +462,7 @@ def list_users(
381462
):
382463
"""
383464
Search users by filtering criteria
465+
384466
:param project: Project name or ID, if provided, results will be for project-level,
385467
otherwise results will be for team level.
386468
:type project: str or int
@@ -4357,6 +4439,10 @@ def item_context(
43574439
:return: An `ItemContext` object to manage the specified item's annotations and metadata.
43584440
:rtype: ItemContext
43594441
4442+
.. seealso::
4443+
For more details, see :class:`ItemContext`.
4444+
4445+
43604446
**Examples:**
43614447
43624448
Create an `ItemContext` using a string path and item name:

0 commit comments

Comments
 (0)