Skip to content

Commit 3072b35

Browse files
authored
slice tag API support (#414)
* retrieve tags through API * add tags support
1 parent 1babbf2 commit 3072b35

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

nucleus/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
PREDICTIONS_PROCESSED_KEY,
110110
REFERENCE_IDS_KEY,
111111
SLICE_ID_KEY,
112+
SLICE_TAGS_KEY,
112113
STATUS_CODE_KEY,
113114
UPDATE_KEY,
114115
)

nucleus/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
STATUS_CODE_KEY = "status_code"
145145
STATUS_KEY = "status"
146146
SUCCESS_STATUS_CODES = [200, 201, 202]
147+
SLICE_TAGS_KEY = "slice_tags"
147148
TAXONOMY_NAME_KEY = "taxonomy_name"
148149
TRACK_REFERENCE_ID_KEY = "track_reference_id"
149150
TRACK_REFERENCE_IDS_KEY = "track_reference_ids"

nucleus/slice.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
from nucleus.annotation import Annotation
1010
from nucleus.async_job import AsyncJob, EmbeddingsExportJob
11-
from nucleus.constants import EXPORT_FOR_TRAINING_KEY, EXPORTED_ROWS, ITEMS_KEY
11+
from nucleus.constants import (
12+
EXPORT_FOR_TRAINING_KEY,
13+
EXPORTED_ROWS,
14+
ITEMS_KEY,
15+
SLICE_TAGS_KEY,
16+
)
1217
from nucleus.dataset_item import DatasetItem
1318
from nucleus.errors import NucleusAPIError
1419
from nucleus.prediction import Prediction
@@ -216,6 +221,10 @@ def dataset_id(self):
216221
self._dataset_id = self.info()["dataset_id"]
217222
return self._dataset_id
218223

224+
@property
225+
def tags(self):
226+
return self.info()["tags"]
227+
219228
@property
220229
def type(self):
221230
"""The type of the Slice."""
@@ -330,6 +339,7 @@ def info(self) -> dict:
330339
"pending_job_count": int
331340
"created_at": datetime
332341
"description": Union[str, None]
342+
"tags":
333343
}
334344
"""
335345
info = KeyErrorDict(
@@ -347,6 +357,25 @@ def info(self) -> dict:
347357
self._description = info["description"]
348358
return info
349359

360+
def add_tags(self, tags: List[str]) -> dict:
361+
"""Tag a slice with custom tag names. ::
362+
363+
import nucleus
364+
client = nucleus.NucleusClient("YOUR_SCALE_API_KEY")
365+
slc = client.get_slice("YOUR_SLICE_ID")
366+
367+
slc.add_tags(["tag_1", "tag_1"])
368+
369+
Args:
370+
tags: list of tag names
371+
"""
372+
response = self._client.make_request(
373+
payload={SLICE_TAGS_KEY: tags},
374+
route=f"slice/{self.id}/tag",
375+
requests_command=requests.post,
376+
)
377+
return response
378+
350379
def append(
351380
self,
352381
reference_ids: Optional[List[str]] = None,

0 commit comments

Comments
 (0)