74
74
import datetime
75
75
import typing
76
76
77
+ from deprecated import deprecated
78
+
77
79
from synapseclient .core .utils import (
78
80
from_unix_epoch_time ,
79
81
id_of ,
@@ -284,6 +286,13 @@ def set_privacy(
284
286
raise KeyError ('The key "%s" couldn\' t be found in the annotations.' % key )
285
287
286
288
289
+ @deprecated (
290
+ version = "4.9.0" ,
291
+ reason = "Use the dataclass model attributes instead. "
292
+ "All dataclass models support annotations: File, Folder, Project, Table, EntityView, Dataset, "
293
+ "DatasetCollection, MaterializedView, SubmissionView, VirtualTable. "
294
+ "Access annotations directly via `instance.annotations` attribute." ,
295
+ )
287
296
class Annotations (dict ):
288
297
"""
289
298
Represent Synapse Entity annotations as a flat dictionary with the system assigned properties id, etag
@@ -295,15 +304,42 @@ class Annotations(dict):
295
304
values: (Optional) dictionary of values to be copied into annotations
296
305
**kwargs: additional key-value pairs to be added as annotations
297
306
298
- Example: Creating a few instances
299
- Creating and setting annotations
300
-
301
- from synapseclient import Annotations
307
+ Example: Migrating from this class to dataclass models
308
+ **Legacy approach (deprecated):**
309
+ ```python
310
+ from synapseclient import Annotations
311
+
312
+ example1 = Annotations('syn123','40256475-6fb3-11ea-bb0a-9cb6d0d8d984', {'foo':'bar'})
313
+ example2 = Annotations('syn123','40256475-6fb3-11ea-bb0a-9cb6d0d8d984', foo='bar')
314
+ example3 = Annotations('syn123','40256475-6fb3-11ea-bb0a-9cb6d0d8d984')
315
+ example3['foo'] = 'bar'
316
+ ```
317
+
318
+ **New approach using dataclass models:**
319
+ ```python
320
+ import synapseclient
321
+ from synapseclient.models import (
322
+ File, Folder, Project, Table, EntityView, Dataset,
323
+ DatasetCollection, MaterializedView, SubmissionView, VirtualTable
324
+ )
302
325
303
- example1 = Annotations('syn123','40256475-6fb3-11ea-bb0a-9cb6d0d8d984', {'foo':'bar'})
304
- example2 = Annotations('syn123','40256475-6fb3-11ea-bb0a-9cb6d0d8d984', foo='bar')
305
- example3 = Annotations('syn123','40256475-6fb3-11ea-bb0a-9cb6d0d8d984')
306
- example3['foo'] = 'bar'
326
+ # Create client and login
327
+ syn = synapseclient.Synapse()
328
+ syn.login()
329
+
330
+ # File - don't download the file content, just get metadata
331
+ file_instance = File(id="syn12345", download_file=False)
332
+ file_instance = file_instance.get()
333
+ file_instance.annotations = {
334
+ "foo": ["bar"],
335
+ "species": ["Homo sapiens"]
336
+ }
337
+ file_instance = file_instance.store()
338
+ print(f"File annotations: {file_instance.annotations}")
339
+
340
+ # All other dataclass models work the same way
341
+ # annotations is always a dict by default (empty {} if no annotations exist)
342
+ ```
307
343
"""
308
344
309
345
id : str
0 commit comments