Skip to content

Synapse Factory Operations

Contained within this file are experimental interfaces for working with the Synapse Python Client. Unless otherwise noted these interfaces are subject to change at any time. Use at your own risk.

API Reference

synapseclient.operations.get

get(synapse_id: Optional[str] = None, *, entity_name: Optional[str] = None, parent_id: Optional[str] = None, version_number: Optional[int] = None, activity_options: Optional[ActivityOptions] = None, file_options: Optional[FileOptions] = None, table_options: Optional[TableOptions] = None, link_options: Optional[LinkOptions] = None, synapse_client: Optional[Synapse] = None) -> Union[Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, SubmissionView, Table, VirtualTable]

Factory method to retrieve any Synapse entity by its ID or by name and parent ID.

This method serves as a unified interface for retrieving any type of Synapse entity without needing to know the specific entity type beforehand. It automatically determines the entity type and returns the appropriate model instance.

You can retrieve entities in two ways:

  1. By providing a synapse_id directly
  2. By providing entity_name and optionally parent_id for lookup
PARAMETER DESCRIPTION
synapse_id

The Synapse ID of the entity to retrieve (e.g., 'syn123456'). Mutually exclusive with entity_name.

TYPE: Optional[str] DEFAULT: None

entity_name

The name of the entity to find. Must be used with this approach instead of synapse_id. When looking up projects, parent_id should be None.

TYPE: Optional[str] DEFAULT: None

parent_id

The parent entity ID when looking up by name. Set to None when looking up projects by name. Only used with entity_name.

TYPE: Optional[str] DEFAULT: None

version_number

The specific version number of the entity to retrieve. Only applies to versionable entities (File, Table, Dataset). If not specified, the most recent version will be retrieved. Ignored for other entity types.

TYPE: Optional[int] DEFAULT: None

activity_options

Activity-specific configuration options. Can be applied to any entity type to include activity information.

TYPE: Optional[ActivityOptions] DEFAULT: None

file_options

File-specific configuration options. Only applies to File entities. Ignored for other entity types.

TYPE: Optional[FileOptions] DEFAULT: None

table_options

Table-specific configuration options. Only applies to Table-like entities (Table, Dataset, EntityView, MaterializedView, SubmissionView, VirtualTable, DatasetCollection). Ignored for other entity types.

TYPE: Optional[TableOptions] DEFAULT: None

link_options

Link-specific configuration options. Only applies when the entity is a Link. Ignored for other entity types.

TYPE: Optional[LinkOptions] DEFAULT: None

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
Union[Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, SubmissionView, Table, VirtualTable]

The appropriate Synapse entity model instance based on the entity type.

RAISES DESCRIPTION
ValueError

If both synapse_id and entity_name are provided, or if neither is provided.

ValueError

If entity_name is provided without this being a valid lookup scenario.

ValueError

If the synapse_id is not a valid Synapse ID format.

Note

When using entity_name lookup:

  • For projects: leave parent_id=None
  • For all other entities: provide the parent_id of the containing folder/project
Retrieving entities by ID

Get any entity by Synapse ID:

from synapseclient import Synapse
from synapseclient.models import File, Project
from synapseclient.operations import get

syn = Synapse()
syn.login()

# Works for any entity type
entity = get(synapse_id="syn123456")

# The returned object will be the appropriate type
if isinstance(entity, File):
    print(f"File: {entity.name}")
elif isinstance(entity, Project):
    print(f"Project: {entity.name}")
Retrieving entities by name

Get an entity by name and parent:

from synapseclient import Synapse
from synapseclient.operations import get

syn = Synapse()
syn.login()

# Get a file by name within a folder
entity = get(
    entity_name="my_file.txt",
    parent_id="syn123456"
)

# Get a project by name (parent_id=None)
project = get(
    entity_name="My Project",
    parent_id=None
)
Retrieving a specific version

Get a specific version of a versionable entity:

from synapseclient import Synapse
from synapseclient.operations import get

syn = Synapse()
syn.login()

entity = get(synapse_id="syn123456", version_number=2)
Retrieving a file with custom options

Get file metadata with specific download options:

from synapseclient import Synapse
from synapseclient.operations import get, FileOptions, ActivityOptions

syn = Synapse()
syn.login()

file_entity = get(
    synapse_id="syn123456",
    activity_options=ActivityOptions(include_activity=True),
    file_options=FileOptions(
        download_file=False
    )
)
Retrieving a table with activity and columns

Get table with activity and column information:

from synapseclient import Synapse
from synapseclient.operations import get, ActivityOptions, TableOptions

syn = Synapse()
syn.login()

table_entity = get(
    synapse_id="syn123456",
    activity_options=ActivityOptions(include_activity=True),
    table_options=TableOptions(include_columns=True)
)
Following links

Get the target of a link entity:

from synapseclient import Synapse
from synapseclient.operations import get, LinkOptions

syn = Synapse()
syn.login()

target_entity = get(
    synapse_id="syn123456",
    link_options=LinkOptions(follow_link=True)
)
Working with Link entities

Get a Link entity without following it:

from synapseclient import Synapse
from synapseclient.operations import get, LinkOptions

syn = Synapse()
syn.login()

# Get the link entity itself
link_entity = get(
    synapse_id="syn123456",  # Example link ID
    link_options=LinkOptions(follow_link=False)
)
print(f"Link: {link_entity.name} -> {link_entity.target_id}")

# Then follow the link to get the target
target_entity = get(
    synapse_id="syn123456",
    link_options=LinkOptions(follow_link=True)
)
print(f"Target: {target_entity.name} (type: {type(target_entity).__name__})")
Comprehensive File options

Download file with custom location and collision handling:

from synapseclient import Synapse
from synapseclient.operations import get, FileOptions

syn = Synapse()
syn.login()

file_entity = get(
    synapse_id="syn123456",
    file_options=FileOptions(
        download_file=True,
        download_location="/path/to/download/",
        if_collision="overwrite.local"
    )
)
print(f"Downloaded file: {file_entity.name} to {file_entity.path}")
Table options for table-like entities

Get table entities with column information:

from synapseclient import Synapse
from synapseclient.operations import get, TableOptions

syn = Synapse()
syn.login()

# Works for Table, Dataset, EntityView, MaterializedView,
# SubmissionView, VirtualTable, and DatasetCollection
table_entity = get(
    synapse_id="syn123456",  # Example table ID
    table_options=TableOptions(include_columns=True)
)
print(f"Table: {table_entity.name} with {len(table_entity.columns)} columns")
Combining multiple options

Get a File with both activity and custom download options:

from synapseclient import Synapse
from synapseclient.operations import get, FileOptions, ActivityOptions

syn = Synapse()
syn.login()

file_entity = get(
    synapse_id="syn123456",
    activity_options=ActivityOptions(include_activity=True),
    file_options=FileOptions(
        download_file=False
    )
)
print(f"File: {file_entity.name} (activity included: {file_entity.activity is not None})")
Working with entity instances

Pass an existing entity instance to refresh or apply new options:

from synapseclient import Synapse
from synapseclient.operations import get, FileOptions

syn = Synapse()
syn.login()

# Get an entity first
entity = get(synapse_id="syn123456")
print(f"Original entity: {entity.name}")

# Then use the entity instance to get it again with different options
refreshed_entity = get(
    entity,
    file_options=FileOptions(download_file=False)
)
print(f"Refreshed entity: {refreshed_entity.name} (download_file: {refreshed_entity.download_file})")
Source code in synapseclient/operations/factory_operations.py
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
def get(
    synapse_id: Optional[str] = None,
    *,
    entity_name: Optional[str] = None,
    parent_id: Optional[str] = None,
    version_number: Optional[int] = None,
    activity_options: Optional[ActivityOptions] = None,
    file_options: Optional[FileOptions] = None,
    table_options: Optional[TableOptions] = None,
    link_options: Optional[LinkOptions] = None,
    synapse_client: Optional["Synapse"] = None,
) -> Union[
    "Dataset",
    "DatasetCollection",
    "EntityView",
    "File",
    "Folder",
    "Link",
    "MaterializedView",
    "Project",
    "SubmissionView",
    "Table",
    "VirtualTable",
]:
    """
    Factory method to retrieve any Synapse entity by its ID or by name and parent ID.

    This method serves as a unified interface for retrieving any type of Synapse entity
    without needing to know the specific entity type beforehand. It automatically
    determines the entity type and returns the appropriate model instance.

    You can retrieve entities in two ways:

    1. By providing a synapse_id directly
    2. By providing entity_name and optionally parent_id for lookup

    Arguments:
        synapse_id: The Synapse ID of the entity to retrieve (e.g., 'syn123456').
            Mutually exclusive with entity_name.
        entity_name: The name of the entity to find. Must be used with this approach
            instead of synapse_id. When looking up projects, parent_id should be None.
        parent_id: The parent entity ID when looking up by name. Set to None when
            looking up projects by name. Only used with entity_name.
        version_number: The specific version number of the entity to retrieve. Only
            applies to versionable entities (File, Table, Dataset). If not specified,
            the most recent version will be retrieved. Ignored for other entity types.
        activity_options: Activity-specific configuration options. Can be applied to
            any entity type to include activity information.
        file_options: File-specific configuration options. Only applies to File entities.
            Ignored for other entity types.
        table_options: Table-specific configuration options. Only applies to Table-like
            entities (Table, Dataset, EntityView, MaterializedView, SubmissionView,
            VirtualTable, DatasetCollection). Ignored for other entity types.
        link_options: Link-specific configuration options. Only applies when the entity
            is a Link. Ignored for other entity types.
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        The appropriate Synapse entity model instance based on the entity type.

    Raises:
        ValueError: If both synapse_id and entity_name are provided, or if neither is provided.
        ValueError: If entity_name is provided without this being a valid lookup scenario.
        ValueError: If the synapse_id is not a valid Synapse ID format.

    Note:
        When using entity_name lookup:

        - For projects: leave parent_id=None
        - For all other entities: provide the parent_id of the containing folder/project

    Example: Retrieving entities by ID
        Get any entity by Synapse ID:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File, Project
        from synapseclient.operations import get

        syn = Synapse()
        syn.login()

        # Works for any entity type
        entity = get(synapse_id="syn123456")

        # The returned object will be the appropriate type
        if isinstance(entity, File):
            print(f"File: {entity.name}")
        elif isinstance(entity, Project):
            print(f"Project: {entity.name}")
        ```

    Example: Retrieving entities by name
        Get an entity by name and parent:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get

        syn = Synapse()
        syn.login()

        # Get a file by name within a folder
        entity = get(
            entity_name="my_file.txt",
            parent_id="syn123456"
        )

        # Get a project by name (parent_id=None)
        project = get(
            entity_name="My Project",
            parent_id=None
        )
        ```

    Example: Retrieving a specific version
        Get a specific version of a versionable entity:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get

        syn = Synapse()
        syn.login()

        entity = get(synapse_id="syn123456", version_number=2)
        ```

    Example: Retrieving a file with custom options
        Get file metadata with specific download options:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, FileOptions, ActivityOptions

        syn = Synapse()
        syn.login()

        file_entity = get(
            synapse_id="syn123456",
            activity_options=ActivityOptions(include_activity=True),
            file_options=FileOptions(
                download_file=False
            )
        )
        ```

    Example: Retrieving a table with activity and columns
        Get table with activity and column information:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, ActivityOptions, TableOptions

        syn = Synapse()
        syn.login()

        table_entity = get(
            synapse_id="syn123456",
            activity_options=ActivityOptions(include_activity=True),
            table_options=TableOptions(include_columns=True)
        )
        ```

    Example: Following links
        Get the target of a link entity:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, LinkOptions

        syn = Synapse()
        syn.login()

        target_entity = get(
            synapse_id="syn123456",
            link_options=LinkOptions(follow_link=True)
        )
        ```

    Example: Working with Link entities
        Get a Link entity without following it:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, LinkOptions

        syn = Synapse()
        syn.login()

        # Get the link entity itself
        link_entity = get(
            synapse_id="syn123456",  # Example link ID
            link_options=LinkOptions(follow_link=False)
        )
        print(f"Link: {link_entity.name} -> {link_entity.target_id}")

        # Then follow the link to get the target
        target_entity = get(
            synapse_id="syn123456",
            link_options=LinkOptions(follow_link=True)
        )
        print(f"Target: {target_entity.name} (type: {type(target_entity).__name__})")
        ```

    Example: Comprehensive File options
        Download file with custom location and collision handling:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, FileOptions

        syn = Synapse()
        syn.login()

        file_entity = get(
            synapse_id="syn123456",
            file_options=FileOptions(
                download_file=True,
                download_location="/path/to/download/",
                if_collision="overwrite.local"
            )
        )
        print(f"Downloaded file: {file_entity.name} to {file_entity.path}")
        ```

    Example: Table options for table-like entities
        Get table entities with column information:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, TableOptions

        syn = Synapse()
        syn.login()

        # Works for Table, Dataset, EntityView, MaterializedView,
        # SubmissionView, VirtualTable, and DatasetCollection
        table_entity = get(
            synapse_id="syn123456",  # Example table ID
            table_options=TableOptions(include_columns=True)
        )
        print(f"Table: {table_entity.name} with {len(table_entity.columns)} columns")
        ```

    Example: Combining multiple options
        Get a File with both activity and custom download options:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, FileOptions, ActivityOptions

        syn = Synapse()
        syn.login()

        file_entity = get(
            synapse_id="syn123456",
            activity_options=ActivityOptions(include_activity=True),
            file_options=FileOptions(
                download_file=False
            )
        )
        print(f"File: {file_entity.name} (activity included: {file_entity.activity is not None})")
        ```

    Example: Working with entity instances
        Pass an existing entity instance to refresh or apply new options:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import get, FileOptions

        syn = Synapse()
        syn.login()

        # Get an entity first
        entity = get(synapse_id="syn123456")
        print(f"Original entity: {entity.name}")

        # Then use the entity instance to get it again with different options
        refreshed_entity = get(
            entity,
            file_options=FileOptions(download_file=False)
        )
        print(f"Refreshed entity: {refreshed_entity.name} (download_file: {refreshed_entity.download_file})")
        ```
    """
    return wrap_async_to_sync(
        coroutine=get_async(
            synapse_id=synapse_id,
            entity_name=entity_name,
            parent_id=parent_id,
            version_number=version_number,
            activity_options=activity_options,
            file_options=file_options,
            table_options=table_options,
            link_options=link_options,
            synapse_client=synapse_client,
        )
    )

synapseclient.operations.FileOptions dataclass

Configuration options specific to File entities when using the factory methods.

This dataclass allows you to customize how File entities are handled during retrieval, including download behavior, file location, and collision handling.

ATTRIBUTE DESCRIPTION
download_file

Whether to automatically download the file content when retrieving the File entity. If True, the file will be downloaded to the local filesystem. If False, only the metadata will be retrieved. Default is True.

TYPE: bool

download_location

The local directory path where the file should be downloaded. If None, the file will be downloaded to the default Synapse cache location. If specified, must be a valid directory path. Default is None.

TYPE: Optional[str]

if_collision

Strategy to use when a file with the same name already exists at the download location. Valid options are: - "keep.both": Keep both files by appending a number to the new file - "overwrite.local": Overwrite the existing local file - "keep.local": Keep the existing local file and skip download Default is "keep.both".

TYPE: str

Example

Configure file download options:

from synapseclient.operations import FileOptions

# Download file to specific location with overwrite
file_options = FileOptions(
    download_file=True,
    download_location="/path/to/downloads/",
    if_collision="overwrite.local"
)

# Only retrieve metadata, don't download file content
metadata_only = FileOptions(download_file=False)
Source code in synapseclient/operations/factory_operations.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@dataclass
class FileOptions:
    """
    Configuration options specific to File entities when using the factory methods.

    This dataclass allows you to customize how File entities are handled during
    retrieval, including download behavior, file location, and collision handling.

    Attributes:
        download_file: Whether to automatically download the file content when
            retrieving the File entity. If True, the file will be downloaded to
            the local filesystem. If False, only the metadata will be retrieved.
            Default is True.
        download_location: The local directory path where the file should be
            downloaded. If None, the file will be downloaded to the default Synapse
            cache location. If specified,
            must be a valid directory path. Default is None.
        if_collision: Strategy to use when a file with the same name already
            exists at the download location. Valid options are:
            - "keep.both": Keep both files by appending a number to the new file
            - "overwrite.local": Overwrite the existing local file
            - "keep.local": Keep the existing local file and skip download
            Default is "keep.both".

    Example:
        Configure file download options:

        ```python
        from synapseclient.operations import FileOptions

        # Download file to specific location with overwrite
        file_options = FileOptions(
            download_file=True,
            download_location="/path/to/downloads/",
            if_collision="overwrite.local"
        )

        # Only retrieve metadata, don't download file content
        metadata_only = FileOptions(download_file=False)
        ```
    """

    download_file: bool = True
    download_location: Optional[str] = None
    if_collision: str = "keep.both"

synapseclient.operations.ActivityOptions dataclass

Configuration options for entities that support activity/provenance tracking.

This dataclass controls whether activity information (provenance data) should be included when retrieving entities. Activity information tracks the computational steps, data sources, and relationships that led to the creation of an entity.

ATTRIBUTE DESCRIPTION
include_activity

Whether to include activity/provenance information when retrieving the entity. If True, the returned entity will have its activity attribute populated with provenance data (if available). If False, the activity attribute will be None. Including activity may result in additional API calls and slower retrieval times. Default is False.

TYPE: bool

Example

Configure activity inclusion:

from synapseclient.operations import ActivityOptions

# Include activity information
with_activity = ActivityOptions(include_activity=True)

# Skip activity information (faster retrieval)
without_activity = ActivityOptions(include_activity=False)
Note

Activity information is only available for entities that support provenance tracking (File, Table, Dataset, etc...). For other entity types, this option is ignored.

Source code in synapseclient/operations/factory_operations.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
@dataclass
class ActivityOptions:
    """
    Configuration options for entities that support activity/provenance tracking.

    This dataclass controls whether activity information (provenance data) should
    be included when retrieving entities. Activity information tracks the computational
    steps, data sources, and relationships that led to the creation of an entity.

    Attributes:
        include_activity: Whether to include activity/provenance information when
            retrieving the entity. If True, the returned entity will have its
            activity attribute populated with provenance data (if available).
            If False, the activity attribute will be None. Including activity
            may result in additional API calls and slower retrieval times.
            Default is False.

    Example:
        Configure activity inclusion:

        ```python
        from synapseclient.operations import ActivityOptions

        # Include activity information
        with_activity = ActivityOptions(include_activity=True)

        # Skip activity information (faster retrieval)
        without_activity = ActivityOptions(include_activity=False)
        ```

    Note:
        Activity information is only available for entities that support provenance
        tracking (File, Table, Dataset, etc...). For other entity
        types, this option is ignored.
    """

    include_activity: bool = False

synapseclient.operations.TableOptions dataclass

Configuration options for table-like entities when using the factory methods.

This dataclass controls how table-like entities (Table, Dataset, EntityView, MaterializedView, SubmissionView, VirtualTable, and DatasetCollection) are retrieved, particularly whether column schema information should be included.

ATTRIBUTE DESCRIPTION
include_columns

Whether to include column schema information when retrieving table-like entities. If True, the returned entity will have its columns attribute populated with Column objects containing schema information (name, column_type, etc.). If False, the columns attribute will be an empty dict. Including columns may result in additional API calls but provides complete table structure information. Default is True.

TYPE: bool

Example

Configure table column inclusion:

from synapseclient.operations import TableOptions

# Include column schema information
with_columns = TableOptions(include_columns=True)

# Skip column information (faster retrieval)
without_columns = TableOptions(include_columns=False)
Source code in synapseclient/operations/factory_operations.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@dataclass
class TableOptions:
    """
    Configuration options for table-like entities when using the factory methods.

    This dataclass controls how table-like entities (Table, Dataset, EntityView,
    MaterializedView, SubmissionView, VirtualTable, and DatasetCollection) are
    retrieved, particularly whether column schema information should be included.

    Attributes:
        include_columns: Whether to include column schema information when
            retrieving table-like entities. If True, the returned entity will
            have its columns attribute populated with Column objects containing
            schema information (name, column_type, etc.). If False, the columns
            attribute will be an empty dict. Including columns may result in
            additional API calls but provides complete table structure information.
            Default is True.

    Example:
        Configure table column inclusion:

        ```python
        from synapseclient.operations import TableOptions

        # Include column schema information
        with_columns = TableOptions(include_columns=True)

        # Skip column information (faster retrieval)
        without_columns = TableOptions(include_columns=False)
        ```
    """

    include_columns: bool = True

synapseclient.operations.LinkOptions dataclass

Configuration options specific to Link entities when using the factory methods.

This dataclass controls how Link entities are handled during retrieval, particularly whether the link should be followed to return the target entity or if the Link entity itself should be returned.

ATTRIBUTE DESCRIPTION
follow_link

Whether to follow the link and return the target entity instead of the Link entity itself. If True, the factory method will return the entity that the Link points to (e.g., if a Link points to a File, a File object will be returned). If False, the Link entity itself will be returned, allowing you to inspect the link's properties such as target_id, target_version, etc. Default is True.

TYPE: bool

Example

Configure link following behavior:

from synapseclient.operations import LinkOptions

# Follow the link and return the target entity
follow_target = LinkOptions(follow_link=True)

# Return the Link entity itself
return_link = LinkOptions(follow_link=False)
Note
  • When follow_link=True, the returned entity type depends on what the Link points to (could be File, Project, Folder, etc.)
  • When follow_link=False, a Link entity is always returned
Source code in synapseclient/operations/factory_operations.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
@dataclass
class LinkOptions:
    """
    Configuration options specific to Link entities when using the factory methods.

    This dataclass controls how Link entities are handled during retrieval,
    particularly whether the link should be followed to return the target entity
    or if the Link entity itself should be returned.

    Attributes:
        follow_link: Whether to follow the link and return the target entity
            instead of the Link entity itself. If True, the factory method will
            return the entity that the Link points to (e.g., if a Link points
            to a File, a File object will be returned). If False, the Link
            entity itself will be returned, allowing you to inspect the link's
            properties such as target_id, target_version, etc. Default is True.

    Example:
        Configure link following behavior:

        ```python
        from synapseclient.operations import LinkOptions

        # Follow the link and return the target entity
        follow_target = LinkOptions(follow_link=True)

        # Return the Link entity itself
        return_link = LinkOptions(follow_link=False)
        ```

    Note:
        - When follow_link=True, the returned entity type depends on what the
          Link points to (could be File, Project, Folder, etc.)
        - When follow_link=False, a Link entity is always returned
    """

    follow_link: bool = True

synapseclient.operations.delete

Factory method to delete any Synapse entity.

This method serves as a unified interface for deleting any type of Synapse entity. It automatically applies the appropriate delete logic based on the entity type.

Version Deletion Behavior

The function supports deleting specific versions of entities with the following precedence order:

  1. version parameter (highest priority): When provided, this version number will be used for deletion, overriding any version information from the entity object or the entity ID string.

  2. Entity's version_number attribute (secondary): If the entity object has a version_number attribute set and no explicit version parameter is provided, this version will be used.

  3. version_only parameter: When set to True, indicates that only a specific version should be deleted (not the entire entity). This parameter is only meaningful when combined with a version number from either the version parameter or the entity's version_number attribute.

Supported for version-specific deletion:

  • String ID with version (e.g., "syn123.4")
  • File, RecordSet (use version_only=True)
  • Table, Dataset, DatasetCollection, EntityView, MaterializedView, SubmissionView, VirtualTable (use version_only=True)

Not supported for version-specific deletion:

  • Project, Folder, Evaluation, Team, SchemaOrganization, CurationTask, Grid
PARAMETER DESCRIPTION
entity

The entity instance to delete, or a Synapse ID string (e.g., "syn123456" or "syn123456.4" for a specific version). Must be one of the supported entity types or a valid Synapse ID.

TYPE: Union[str, CurationTask, Dataset, DatasetCollection, EntityView, Evaluation, File, Folder, Grid, JSONSchema, MaterializedView, Project, RecordSet, SchemaOrganization, SubmissionView, Table, Team, VirtualTable]

version

Optional version number to delete. Takes precedence over any version information in the entity object or ID string. When provided with version_only=True, deletes only this specific version.

TYPE: Optional[Union[int, str]] DEFAULT: None

version_only

If True, only the specified version will be deleted, not the entire entity. Requires a version number from either the version parameter or the entity's version_number attribute. This parameter is applicable for entities that support version-specific deletion (File, RecordSet, Table, Dataset, DatasetCollection, EntityView, MaterializedView, SubmissionView, VirtualTable, JSONSchema).

TYPE: bool DEFAULT: False

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
None

None

RAISES DESCRIPTION
ValueError

If the entity is not a supported type or not a valid Synapse ID.

ValueError

If version_only is True but no version number is available.

Deleting a file by object

Delete a file from Synapse:

from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import delete

syn = Synapse()
syn.login()

file = File(id="syn123456")
delete(file)
print("File deleted successfully")
Deleting a specific version of a file

Delete only version 2 of a file, keeping other versions:

from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import delete

syn = Synapse()
syn.login()

# Method 1: Using version parameter (highest priority)
file = File(id="syn123456")
delete(file, version=2, version_only=True)

# Method 2: Using entity's version_number attribute
file = File(id="syn123456", version_number=2)
delete(file, version_only=True)

# Method 3: Using synapse ID with version
delete("syn123456.2", version_only=True)
print("File version 2 deleted successfully")
Deleting a file by ID string

Delete a file from Synapse using just its ID:

from synapseclient import Synapse
from synapseclient.operations import delete

syn = Synapse()
syn.login()

delete("syn123456")
print("Entity deleted successfully")
Deleting a project

Delete a project from Synapse:

from synapseclient import Synapse
from synapseclient.models import Project
from synapseclient.operations import delete

syn = Synapse()
syn.login()

project = Project(id="syn123456")
delete(project)
print("Project deleted successfully")
Deleting a specific version of a RecordSet

Delete only a specific version of a RecordSet:

from synapseclient import Synapse
from synapseclient.models import RecordSet
from synapseclient.operations import delete

syn = Synapse()
syn.login()

record_set = RecordSet(id="syn123456", version_number=3)
delete(record_set, version_only=True)
print("RecordSet version 3 deleted successfully")
Deleting a table

Delete a table from Synapse:

from synapseclient import Synapse
from synapseclient.models import Table
from synapseclient.operations import delete

syn = Synapse()
syn.login()

table = Table(id="syn123456")
delete(table)
print("Table deleted successfully")
Deleting a team

Delete a team from Synapse:

from synapseclient import Synapse
from synapseclient.models import Team
from synapseclient.operations import delete

syn = Synapse()
syn.login()

team = Team(id="123456")
delete(team)
print("Team deleted successfully")
Deleting a curation task

Delete a curation task from Synapse:

from synapseclient import Synapse
from synapseclient.models import CurationTask
from synapseclient.operations import delete

syn = Synapse()
syn.login()

task = CurationTask(task_id=123)
delete(task)
print("Curation task deleted successfully")
Source code in synapseclient/operations/delete_operations.py
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
def delete(
    entity: Union[
        str,
        "CurationTask",
        "Dataset",
        "DatasetCollection",
        "EntityView",
        "Evaluation",
        "File",
        "Folder",
        "Grid",
        "JSONSchema",
        "MaterializedView",
        "Project",
        "RecordSet",
        "SchemaOrganization",
        "SubmissionView",
        "Table",
        "Team",
        "VirtualTable",
    ],
    version: Optional[Union[int, str]] = None,
    version_only: bool = False,
    *,
    synapse_client: Optional["Synapse"] = None,
) -> None:
    """
    Factory method to delete any Synapse entity.

    This method serves as a unified interface for deleting any type of Synapse entity.
    It automatically applies the appropriate delete logic based on the entity type.

    Version Deletion Behavior:
        The function supports deleting specific versions of entities with the following
        precedence order:

        1. **version parameter** (highest priority): When provided, this version number
           will be used for deletion, overriding any version information from the entity
           object or the entity ID string.

        2. **Entity's version_number attribute** (secondary): If the entity object has
           a `version_number` attribute set and no explicit `version` parameter is
           provided, this version will be used.

        3. **version_only parameter**: When set to True, indicates that only a specific
           version should be deleted (not the entire entity). This parameter is only
           meaningful when combined with a version number from either the `version`
           parameter or the entity's `version_number` attribute.

        **Supported for version-specific deletion:**

        - String ID with version (e.g., "syn123.4")
        - File, RecordSet (use version_only=True)
        - Table, Dataset, DatasetCollection, EntityView, MaterializedView,
          SubmissionView, VirtualTable (use version_only=True)

        **Not supported for version-specific deletion:**

        - Project, Folder, Evaluation, Team, SchemaOrganization, CurationTask, Grid

    Arguments:
        entity: The entity instance to delete, or a Synapse ID string (e.g., "syn123456"
            or "syn123456.4" for a specific version). Must be one of the supported
            entity types or a valid Synapse ID.
        version: Optional version number to delete. Takes precedence over any version
            information in the entity object or ID string. When provided with
            `version_only=True`, deletes only this specific version.
        version_only: If True, only the specified version will be deleted, not the
            entire entity. Requires a version number from either the `version` parameter
            or the entity's `version_number` attribute. This parameter is applicable for
            entities that support version-specific deletion (File, RecordSet, Table,
            Dataset, DatasetCollection, EntityView, MaterializedView, SubmissionView,
            VirtualTable, JSONSchema).
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        None

    Raises:
        ValueError: If the entity is not a supported type or not a valid Synapse ID.
        ValueError: If version_only is True but no version number is available.

    Example: Deleting a file by object
        Delete a file from Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        file = File(id="syn123456")
        delete(file)
        print("File deleted successfully")
        ```

    Example: Deleting a specific version of a file
        Delete only version 2 of a file, keeping other versions:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        # Method 1: Using version parameter (highest priority)
        file = File(id="syn123456")
        delete(file, version=2, version_only=True)

        # Method 2: Using entity's version_number attribute
        file = File(id="syn123456", version_number=2)
        delete(file, version_only=True)

        # Method 3: Using synapse ID with version
        delete("syn123456.2", version_only=True)
        print("File version 2 deleted successfully")
        ```

    Example: Deleting a file by ID string
        Delete a file from Synapse using just its ID:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        delete("syn123456")
        print("Entity deleted successfully")
        ```

    Example: Deleting a project
        Delete a project from Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Project
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        project = Project(id="syn123456")
        delete(project)
        print("Project deleted successfully")
        ```

    Example: Deleting a specific version of a RecordSet
        Delete only a specific version of a RecordSet:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import RecordSet
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        record_set = RecordSet(id="syn123456", version_number=3)
        delete(record_set, version_only=True)
        print("RecordSet version 3 deleted successfully")
        ```

    Example: Deleting a table
        Delete a table from Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Table
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        table = Table(id="syn123456")
        delete(table)
        print("Table deleted successfully")
        ```

    Example: Deleting a team
        Delete a team from Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Team
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        team = Team(id="123456")
        delete(team)
        print("Team deleted successfully")
        ```

    Example: Deleting a curation task
        Delete a curation task from Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import CurationTask
        from synapseclient.operations import delete

        syn = Synapse()
        syn.login()

        task = CurationTask(task_id=123)
        delete(task)
        print("Curation task deleted successfully")
        ```
    """
    return wrap_async_to_sync(
        coroutine=delete_async(
            entity=entity,
            version=version,
            version_only=version_only,
            synapse_client=synapse_client,
        )
    )

synapseclient.operations.store

Factory method to store any Synapse entity.

This method serves as a unified interface for storing any type of Synapse entity. It automatically applies the appropriate store logic based on the entity type and the options provided.

PARAMETER DESCRIPTION
entity

The entity instance to store. Must be one of the supported entity types.

TYPE: Union[AgentSession, CurationTask, Dataset, DatasetCollection, EntityView, Evaluation, File, Folder, FormData, FormGroup, Grid, JSONSchema, Link, MaterializedView, Project, RecordSet, SchemaOrganization, SubmissionView, Table, Team, VirtualTable]

parent

The parent folder or project to store the entity in. Only applicable for File, Folder, Link, and RecordSet entities. Ignored for other entity types.

TYPE: Optional[Union[Folder, Project]] DEFAULT: None

file_options

File-specific configuration options. Only applies to File and RecordSet entities. Ignored for other entity types.

TYPE: Optional[StoreFileOptions] DEFAULT: None

container_options

Container-specific configuration options. Only applies to Project and Folder entities. Ignored for other entity types.

TYPE: Optional[StoreContainerOptions] DEFAULT: None

table_options

Table-specific configuration options. Only applies to Table-like entities (Table, Dataset, EntityView, MaterializedView, SubmissionView, VirtualTable, DatasetCollection). Ignored for other entity types.

TYPE: Optional[StoreTableOptions] DEFAULT: None

json_schema_options

JSONSchema-specific configuration options. Only applies to JSONSchema entities. Required for JSONSchema. Ignored for other entity types.

TYPE: Optional[StoreJSONSchemaOptions] DEFAULT: None

grid_options

Grid-specific configuration options. Only applies to Grid entities. Ignored for other entity types.

TYPE: Optional[StoreGridOptions] DEFAULT: None

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
Union[AgentSession, CurationTask, Dataset, DatasetCollection, EntityView, Evaluation, File, Folder, FormData, FormGroup, Grid, JSONSchema, Link, MaterializedView, Project, RecordSet, SchemaOrganization, SubmissionView, Table, Team, VirtualTable]

The stored Synapse entity model instance.

RAISES DESCRIPTION
ValueError

If the entity is not a supported type.

Storing a file

Store a file to Synapse:

from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import store

syn = Synapse()
syn.login()

file = File(path="/path/to/file.txt", parent_id="syn123456")
stored_file = store(file)
print(f"Stored file: {stored_file.name} (ID: {stored_file.id})")
Storing a file with custom options

Store a file with custom options:

from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import store, StoreFileOptions

syn = Synapse()
syn.login()

file = File(path="/path/to/file.txt", parent_id="syn123456")
stored_file = store(
    file,
    file_options=StoreFileOptions(
        synapse_store=True,
        content_type="text/plain",
        merge_existing_annotations=True
    )
)
print(f"Stored file: {stored_file.name}")
Storing a folder

Store a folder to Synapse:

from synapseclient import Synapse
from synapseclient.models import Folder
from synapseclient.operations import store

syn = Synapse()
syn.login()

folder = Folder(name="My Folder", parent_id="syn123456")
stored_folder = store(folder)
print(f"Stored folder: {stored_folder.name} (ID: {stored_folder.id})")
Storing a project

Store a project to Synapse:

from synapseclient import Synapse
from synapseclient.models import Project
from synapseclient.operations import store

syn = Synapse()
syn.login()

project = Project(name="My Project")
stored_project = store(project)
print(f"Stored project: {stored_project.name} (ID: {stored_project.id})")
Storing a table

Store a table to Synapse:

from synapseclient import Synapse
from synapseclient.models import Table, Column, ColumnType
from synapseclient.operations import store, StoreTableOptions

syn = Synapse()
syn.login()

table = Table(
    name="My Table",
    parent_id="syn123456",
    columns=[Column(name="col1", column_type=ColumnType.STRING, maximum_size=50)]
)
stored_table = store(
    table,
    table_options=StoreTableOptions(dry_run=False, job_timeout=600)
)
print(f"Stored table: {stored_table.name} (ID: {stored_table.id})")
Storing a link

Store a link to Synapse:

from synapseclient import Synapse
from synapseclient.models import Link
from synapseclient.operations import store

syn = Synapse()
syn.login()

link = Link(name="My Link", parent_id="syn123456", target_id="syn789")
stored_link = store(link)
print(f"Stored link: {stored_link.name} (ID: {stored_link.id})")
Storing with parent parameter

Store an entity by passing the parent as a parameter:

from synapseclient import Synapse
from synapseclient.models import File, Folder
from synapseclient.operations import store

syn = Synapse()
syn.login()

parent_folder = Folder(id="syn123456")
file = File(path="/path/to/file.txt")
stored_file = store(file, parent=parent_folder)
print(f"Stored file: {stored_file.name} in folder {parent_folder.id}")
Storing an Evaluation

Store an evaluation (challenge queue):

from synapseclient import Synapse
from synapseclient.models import Evaluation
from synapseclient.operations import store

syn = Synapse()
syn.login()

evaluation = Evaluation(
    name="My Challenge Evaluation",
    description="Evaluation for my data challenge",
    content_source="syn123456"
)
stored_evaluation = store(evaluation)
print(f"Stored evaluation: {stored_evaluation.name} (ID: {stored_evaluation.id})")
Creating a Team

Create a new team (note: Teams use create, not update):

from synapseclient import Synapse
from synapseclient.models import Team
from synapseclient.operations import store

syn = Synapse()
syn.login()

team = Team(
    name="My Research Team",
    description="A team for collaborative research"
)
created_team = store(team)
print(f"Created team: {created_team.name} (ID: {created_team.id})")
Storing a CurationTask

Store a curation task:

from synapseclient import Synapse
from synapseclient.models import CurationTask, FileBasedMetadataTaskProperties
from synapseclient.operations import store

syn = Synapse()
syn.login()

file_properties = FileBasedMetadataTaskProperties(
    upload_folder_id="syn1234567",
    file_view_id="syn2345678"
)
task = CurationTask(
    project_id="syn9876543",
    data_type="genomics_data",
    instructions="Upload your genomics files",
    task_properties=file_properties
)
stored_task = store(task)
print(f"Stored curation task: {stored_task.task_id}")
Source code in synapseclient/operations/store_operations.py
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
def store(
    entity: Union[
        "AgentSession",
        "CurationTask",
        "Dataset",
        "DatasetCollection",
        "EntityView",
        "Evaluation",
        "File",
        "Folder",
        "FormData",
        "FormGroup",
        "Grid",
        "JSONSchema",
        "Link",
        "MaterializedView",
        "Project",
        "RecordSet",
        "SchemaOrganization",
        "SubmissionView",
        "Table",
        "Team",
        "VirtualTable",
    ],
    parent: Optional[Union["Folder", "Project"]] = None,
    *,
    file_options: Optional[StoreFileOptions] = None,
    container_options: Optional[StoreContainerOptions] = None,
    table_options: Optional[StoreTableOptions] = None,
    json_schema_options: Optional[StoreJSONSchemaOptions] = None,
    grid_options: Optional[StoreGridOptions] = None,
    synapse_client: Optional["Synapse"] = None,
) -> Union[
    "AgentSession",
    "CurationTask",
    "Dataset",
    "DatasetCollection",
    "EntityView",
    "Evaluation",
    "File",
    "Folder",
    "FormData",
    "FormGroup",
    "Grid",
    "JSONSchema",
    "Link",
    "MaterializedView",
    "Project",
    "RecordSet",
    "SchemaOrganization",
    "SubmissionView",
    "Table",
    "Team",
    "VirtualTable",
]:
    """
    Factory method to store any Synapse entity.

    This method serves as a unified interface for storing any type of Synapse entity.
    It automatically applies the appropriate store logic based on the entity type and
    the options provided.

    Arguments:
        entity: The entity instance to store. Must be one of the supported entity types.
        parent: The parent folder or project to store the entity in. Only applicable
            for File, Folder, Link, and RecordSet entities. Ignored for other entity types.
        file_options: File-specific configuration options. Only applies to File and
            RecordSet entities. Ignored for other entity types.
        container_options: Container-specific configuration options. Only applies to
            Project and Folder entities. Ignored for other entity types.
        table_options: Table-specific configuration options. Only applies to Table-like
            entities (Table, Dataset, EntityView, MaterializedView, SubmissionView,
            VirtualTable, DatasetCollection). Ignored for other entity types.
        json_schema_options: JSONSchema-specific configuration options. Only applies to
            JSONSchema entities. Required for JSONSchema. Ignored for other entity types.
        grid_options: Grid-specific configuration options. Only applies to Grid entities.
            Ignored for other entity types.
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        The stored Synapse entity model instance.

    Raises:
        ValueError: If the entity is not a supported type.

    Example: Storing a file
        Store a file to Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        file = File(path="/path/to/file.txt", parent_id="syn123456")
        stored_file = store(file)
        print(f"Stored file: {stored_file.name} (ID: {stored_file.id})")
        ```

    Example: Storing a file with custom options
        Store a file with custom options:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File
        from synapseclient.operations import store, StoreFileOptions

        syn = Synapse()
        syn.login()

        file = File(path="/path/to/file.txt", parent_id="syn123456")
        stored_file = store(
            file,
            file_options=StoreFileOptions(
                synapse_store=True,
                content_type="text/plain",
                merge_existing_annotations=True
            )
        )
        print(f"Stored file: {stored_file.name}")
        ```

    Example: Storing a folder
        Store a folder to Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Folder
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        folder = Folder(name="My Folder", parent_id="syn123456")
        stored_folder = store(folder)
        print(f"Stored folder: {stored_folder.name} (ID: {stored_folder.id})")
        ```

    Example: Storing a project
        Store a project to Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Project
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        project = Project(name="My Project")
        stored_project = store(project)
        print(f"Stored project: {stored_project.name} (ID: {stored_project.id})")
        ```

    Example: Storing a table
        Store a table to Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Table, Column, ColumnType
        from synapseclient.operations import store, StoreTableOptions

        syn = Synapse()
        syn.login()

        table = Table(
            name="My Table",
            parent_id="syn123456",
            columns=[Column(name="col1", column_type=ColumnType.STRING, maximum_size=50)]
        )
        stored_table = store(
            table,
            table_options=StoreTableOptions(dry_run=False, job_timeout=600)
        )
        print(f"Stored table: {stored_table.name} (ID: {stored_table.id})")
        ```

    Example: Storing a link
        Store a link to Synapse:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Link
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        link = Link(name="My Link", parent_id="syn123456", target_id="syn789")
        stored_link = store(link)
        print(f"Stored link: {stored_link.name} (ID: {stored_link.id})")
        ```

    Example: Storing with parent parameter
        Store an entity by passing the parent as a parameter:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File, Folder
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        parent_folder = Folder(id="syn123456")
        file = File(path="/path/to/file.txt")
        stored_file = store(file, parent=parent_folder)
        print(f"Stored file: {stored_file.name} in folder {parent_folder.id}")
        ```

    Example: Storing an Evaluation
        Store an evaluation (challenge queue):

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Evaluation
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        evaluation = Evaluation(
            name="My Challenge Evaluation",
            description="Evaluation for my data challenge",
            content_source="syn123456"
        )
        stored_evaluation = store(evaluation)
        print(f"Stored evaluation: {stored_evaluation.name} (ID: {stored_evaluation.id})")
        ```

    Example: Creating a Team
        Create a new team (note: Teams use create, not update):

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Team
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        team = Team(
            name="My Research Team",
            description="A team for collaborative research"
        )
        created_team = store(team)
        print(f"Created team: {created_team.name} (ID: {created_team.id})")
        ```

    Example: Storing a CurationTask
        Store a curation task:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import CurationTask, FileBasedMetadataTaskProperties
        from synapseclient.operations import store

        syn = Synapse()
        syn.login()

        file_properties = FileBasedMetadataTaskProperties(
            upload_folder_id="syn1234567",
            file_view_id="syn2345678"
        )
        task = CurationTask(
            project_id="syn9876543",
            data_type="genomics_data",
            instructions="Upload your genomics files",
            task_properties=file_properties
        )
        stored_task = store(task)
        print(f"Stored curation task: {stored_task.task_id}")
        ```
    """
    return wrap_async_to_sync(
        coroutine=store_async(
            entity=entity,
            parent=parent,
            file_options=file_options,
            container_options=container_options,
            table_options=table_options,
            json_schema_options=json_schema_options,
            grid_options=grid_options,
            synapse_client=synapse_client,
        )
    )

synapseclient.operations.StoreFileOptions dataclass

Options for storing File entities.

ATTRIBUTE DESCRIPTION
synapse_store

Whether to store the file in Synapse or use an external URL.

TYPE: Optional[bool]

content_type

The content type of the file.

TYPE: Optional[str]

merge_existing_annotations

If True, merge existing annotations with new ones. If False, replace all annotations.

TYPE: Optional[bool]

associate_activity_to_new_version

If True, associate activity with new version. If False, do not associate activity.

TYPE: Optional[bool]

Source code in synapseclient/operations/store_operations.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@dataclass
class StoreFileOptions:
    """Options for storing File entities.

    Attributes:
        synapse_store: Whether to store the file in Synapse or use an external URL.
        content_type: The content type of the file.
        merge_existing_annotations: If True, merge existing annotations with new ones.
            If False, replace all annotations.
        associate_activity_to_new_version: If True, associate activity with new version.
            If False, do not associate activity.
    """

    synapse_store: Optional[bool] = None
    content_type: Optional[str] = None
    merge_existing_annotations: Optional[bool] = None
    associate_activity_to_new_version: Optional[bool] = None

synapseclient.operations.StoreContainerOptions dataclass

Options for storing container entities (Project, Folder).

ATTRIBUTE DESCRIPTION
failure_strategy

Strategy for handling failures when storing child entities. Can be either a FailureStrategy enum value or a string. Valid string values: "LOG_EXCEPTION", "RAISE_EXCEPTION". Valid enum values: FailureStrategy.LOG_EXCEPTION, FailureStrategy.RAISE_EXCEPTION.

TYPE: Optional[Union[str, FailureStrategy]]

Source code in synapseclient/operations/store_operations.py
55
56
57
58
59
60
61
62
63
64
65
66
@dataclass
class StoreContainerOptions:
    """Options for storing container entities (Project, Folder).

    Attributes:
        failure_strategy: Strategy for handling failures when storing child entities.
            Can be either a FailureStrategy enum value or a string.
            Valid string values: "LOG_EXCEPTION", "RAISE_EXCEPTION".
            Valid enum values: FailureStrategy.LOG_EXCEPTION, FailureStrategy.RAISE_EXCEPTION.
    """

    failure_strategy: Optional[Union[str, FailureStrategy]] = None

synapseclient.operations.StoreTableOptions dataclass

Options for storing Table-like entities.

ATTRIBUTE DESCRIPTION
dry_run

If True, will not actually store but will log what would be done.

TYPE: bool

job_timeout

Maximum time to wait for table schema update job to complete.

TYPE: int

Source code in synapseclient/operations/store_operations.py
69
70
71
72
73
74
75
76
77
78
79
@dataclass
class StoreTableOptions:
    """Options for storing Table-like entities.

    Attributes:
        dry_run: If True, will not actually store but will log what would be done.
        job_timeout: Maximum time to wait for table schema update job to complete.
    """

    dry_run: bool = False
    job_timeout: int = 600

synapseclient.operations.StoreJSONSchemaOptions dataclass

Options for storing JSONSchema entities.

ATTRIBUTE DESCRIPTION
schema_body

The body of the JSONSchema to store.

TYPE: dict

version

The version of the JSONSchema body to store.

TYPE: Optional[str]

dry_run

Whether or not to do a dry-run.

TYPE: bool

Source code in synapseclient/operations/store_operations.py
82
83
84
85
86
87
88
89
90
91
92
93
94
@dataclass
class StoreJSONSchemaOptions:
    """Options for storing JSONSchema entities.

    Attributes:
        schema_body: The body of the JSONSchema to store.
        version: The version of the JSONSchema body to store.
        dry_run: Whether or not to do a dry-run.
    """

    schema_body: dict
    version: Optional[str] = None
    dry_run: bool = False

synapseclient.operations.StoreGridOptions dataclass

Options for storing Grid entities.

ATTRIBUTE DESCRIPTION
attach_to_previous_session

If True and using record_set_id, will attach to an existing active session if one exists.

TYPE: bool

timeout

The number of seconds to wait for the job to complete.

TYPE: int

Source code in synapseclient/operations/store_operations.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
@dataclass
class StoreGridOptions:
    """Options for storing Grid entities.

    Attributes:
        attach_to_previous_session: If True and using record_set_id, will attach
            to an existing active session if one exists.
        timeout: The number of seconds to wait for the job to complete.
    """

    attach_to_previous_session: bool = False
    timeout: int = 120

synapseclient.operations.find_entity_id

find_entity_id(name: str, parent: Optional[Union[str, Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable]] = None, *, synapse_client: Optional[Synapse] = None) -> Optional[str]

Find an Entity given its name and parent.

PARAMETER DESCRIPTION
name

Name of the entity to find.

TYPE: str

parent

An Entity object (Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable) or the Id of an entity as a string. Omit if searching for a Project by name.

TYPE: Optional[Union[str, Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable]] DEFAULT: None

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
Optional[str]

The Entity ID or None if not found.

Finding a project by name

Find a project using only its name:

from synapseclient import Synapse
from synapseclient.operations import find_entity_id

syn = Synapse()
syn.login()

project_id = find_entity_id(name="My Project")
if project_id:
    print(f"Found project: {project_id}")
else:
    print("Project not found")
Finding an entity within a parent

Find a file within a specific folder:

from synapseclient import Synapse
from synapseclient.operations import find_entity_id

syn = Synapse()
syn.login()

file_id = find_entity_id(
    name="my_data.csv",
    parent="syn123456"  # Parent folder ID
)
if file_id:
    print(f"Found file: {file_id}")
else:
    print("File not found in folder")
Using with entity objects

Find an entity using an entity object as the parent:

from synapseclient import Synapse
from synapseclient.models import Folder
from synapseclient.operations import find_entity_id

syn = Synapse()
syn.login()

parent_folder = Folder(id="syn123456")
entity_id = find_entity_id(
    name="analysis_results.txt",
    parent=parent_folder
)
print(f"Entity ID: {entity_id}")
Source code in synapseclient/operations/utility_operations.py
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def find_entity_id(
    name: str,
    parent: Optional[
        Union[
            str,
            "Dataset",
            "DatasetCollection",
            "EntityView",
            "File",
            "Folder",
            "Link",
            "MaterializedView",
            "Project",
            "RecordSet",
            "SubmissionView",
            "Table",
            "VirtualTable",
        ]
    ] = None,
    *,
    synapse_client: Optional["Synapse"] = None,
) -> Optional[str]:
    """
    Find an Entity given its name and parent.

    Arguments:
        name: Name of the entity to find.
        parent: An Entity object (Dataset, DatasetCollection, EntityView, File,
            Folder, Link, MaterializedView, Project, RecordSet, SubmissionView,
            Table, VirtualTable) or the Id of an entity as a string. Omit if
            searching for a Project by name.
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        The Entity ID or None if not found.

    Example: Finding a project by name
        Find a project using only its name:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import find_entity_id

        syn = Synapse()
        syn.login()

        project_id = find_entity_id(name="My Project")
        if project_id:
            print(f"Found project: {project_id}")
        else:
            print("Project not found")
        ```

    Example: Finding an entity within a parent
        Find a file within a specific folder:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import find_entity_id

        syn = Synapse()
        syn.login()

        file_id = find_entity_id(
            name="my_data.csv",
            parent="syn123456"  # Parent folder ID
        )
        if file_id:
            print(f"Found file: {file_id}")
        else:
            print("File not found in folder")
        ```

    Example: Using with entity objects
        Find an entity using an entity object as the parent:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import Folder
        from synapseclient.operations import find_entity_id

        syn = Synapse()
        syn.login()

        parent_folder = Folder(id="syn123456")
        entity_id = find_entity_id(
            name="analysis_results.txt",
            parent=parent_folder
        )
        print(f"Entity ID: {entity_id}")
        ```
    """
    return wrap_async_to_sync(
        coroutine=find_entity_id_async(
            name=name,
            parent=parent,
            synapse_client=synapse_client,
        )
    )

synapseclient.operations.is_synapse_id

is_synapse_id(syn_id: str, *, synapse_client: Optional[Synapse] = None) -> bool

Check if given synID is valid (attached to actual entity).

PARAMETER DESCRIPTION
syn_id

A Synapse ID to validate.

TYPE: str

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
bool

True if the Synapse ID is valid.

Validating a Synapse ID

Check if a Synapse ID exists:

from synapseclient import Synapse
from synapseclient.operations import is_synapse_id

syn = Synapse()
syn.login()

if is_synapse_id("syn123456"):
    print("Valid Synapse ID")
else:
    print("Invalid or non-existent Synapse ID")
Validating multiple IDs

Check multiple Synapse IDs in a loop:

from synapseclient import Synapse
from synapseclient.operations import is_synapse_id

syn = Synapse()
syn.login()

ids_to_check = ["syn123456", "syn999999", "syn789012"]
for synapse_id in ids_to_check:
    if is_synapse_id(synapse_id):
        print(f"{synapse_id} is valid")
    else:
        print(f"{synapse_id} is invalid or does not exist")
Using in conditional logic

Use ID validation before attempting operations:

from synapseclient import Synapse
from synapseclient.operations import is_synapse_id, get

syn = Synapse()
syn.login()

user_input = "syn123456"
if is_synapse_id(user_input):
    entity = get(synapse_id=user_input)
    print(f"Retrieved entity: {entity.name}")
else:
    print("Please provide a valid Synapse ID")
Source code in synapseclient/operations/utility_operations.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
def is_synapse_id(
    syn_id: str,
    *,
    synapse_client: Optional["Synapse"] = None,
) -> bool:
    """
    Check if given synID is valid (attached to actual entity).

    Arguments:
        syn_id: A Synapse ID to validate.
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        True if the Synapse ID is valid.

    Example: Validating a Synapse ID
        Check if a Synapse ID exists:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import is_synapse_id

        syn = Synapse()
        syn.login()

        if is_synapse_id("syn123456"):
            print("Valid Synapse ID")
        else:
            print("Invalid or non-existent Synapse ID")
        ```

    Example: Validating multiple IDs
        Check multiple Synapse IDs in a loop:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import is_synapse_id

        syn = Synapse()
        syn.login()

        ids_to_check = ["syn123456", "syn999999", "syn789012"]
        for synapse_id in ids_to_check:
            if is_synapse_id(synapse_id):
                print(f"{synapse_id} is valid")
            else:
                print(f"{synapse_id} is invalid or does not exist")
        ```

    Example: Using in conditional logic
        Use ID validation before attempting operations:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import is_synapse_id, get

        syn = Synapse()
        syn.login()

        user_input = "syn123456"
        if is_synapse_id(user_input):
            entity = get(synapse_id=user_input)
            print(f"Retrieved entity: {entity.name}")
        else:
            print("Please provide a valid Synapse ID")
        ```
    """
    return wrap_async_to_sync(
        coroutine=is_synapse_id_async(
            syn_id=syn_id,
            synapse_client=synapse_client,
        )
    )

synapseclient.operations.onweb

onweb(entity: Union[str, Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable], subpage_id: Optional[str] = None, *, synapse_client: Optional[Synapse] = None) -> str

Open up a browser window to the entity page or wiki-subpage.

PARAMETER DESCRIPTION
entity

Either an Entity object (Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable) or a Synapse ID string.

TYPE: Union[str, Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable]

subpage_id

(Optional) ID of one of the wiki's sub-pages.

TYPE: Optional[str] DEFAULT: None

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
str

The URL that was opened in the browser.

Opening an entity in browser

Open an entity's page in the default web browser:

from synapseclient import Synapse
from synapseclient.operations import onweb

syn = Synapse()
syn.login()

# Open by Synapse ID
url = onweb("syn123456")
print(f"Opened: {url}")
Opening with an entity object

Open an entity using an entity object:

from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import onweb, get

syn = Synapse()
syn.login()

file = get(synapse_id="syn123456")
url = onweb(file)
print(f"Opened file: {url}")
Opening a wiki subpage

Open a specific wiki subpage:

from synapseclient import Synapse
from synapseclient.operations import onweb

syn = Synapse()
syn.login()

# Open a specific wiki subpage
url = onweb("syn123456", subpage_id="12345")
print(f"Opened wiki subpage: {url}")
Source code in synapseclient/operations/utility_operations.py
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
def onweb(
    entity: Union[
        str,
        "Dataset",
        "DatasetCollection",
        "EntityView",
        "File",
        "Folder",
        "Link",
        "MaterializedView",
        "Project",
        "RecordSet",
        "SubmissionView",
        "Table",
        "VirtualTable",
    ],
    subpage_id: Optional[str] = None,
    *,
    synapse_client: Optional["Synapse"] = None,
) -> str:
    """
    Open up a browser window to the entity page or wiki-subpage.

    Arguments:
        entity: Either an Entity object (Dataset, DatasetCollection, EntityView,
            File, Folder, Link, MaterializedView, Project, RecordSet,
            SubmissionView, Table, VirtualTable) or a Synapse ID string.
        subpage_id: (Optional) ID of one of the wiki's sub-pages.
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        The URL that was opened in the browser.

    Example: Opening an entity in browser
        Open an entity's page in the default web browser:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import onweb

        syn = Synapse()
        syn.login()

        # Open by Synapse ID
        url = onweb("syn123456")
        print(f"Opened: {url}")
        ```

    Example: Opening with an entity object
        Open an entity using an entity object:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File
        from synapseclient.operations import onweb, get

        syn = Synapse()
        syn.login()

        file = get(synapse_id="syn123456")
        url = onweb(file)
        print(f"Opened file: {url}")
        ```

    Example: Opening a wiki subpage
        Open a specific wiki subpage:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import onweb

        syn = Synapse()
        syn.login()

        # Open a specific wiki subpage
        url = onweb("syn123456", subpage_id="12345")
        print(f"Opened wiki subpage: {url}")
        ```
    """
    return wrap_async_to_sync(
        coroutine=onweb_async(
            entity=entity,
            subpage_id=subpage_id,
            synapse_client=synapse_client,
        )
    )

synapseclient.operations.md5_query

md5_query(md5: str, *, synapse_client: Optional[Synapse] = None) -> List[dict]

Find the Entities which have attached file(s) which have the given MD5 hash.

PARAMETER DESCRIPTION
md5

The MD5 hash to query for (hexadecimal string).

TYPE: str

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
List[dict]

A list of Entity headers matching the MD5 hash.

Finding entities by MD5 hash

Search for entities with a specific MD5 hash:

from synapseclient import Synapse
from synapseclient.operations import md5_query

syn = Synapse()
syn.login()

md5_hash = "1234567890abcdef1234567890abcdef"
results = md5_query(md5_hash)

print(f"Found {len(results)} entities with MD5: {md5_hash}")
for entity in results:
    print(f"- {entity['id']}: {entity['name']}")
Checking for duplicate files

Use MD5 query to find duplicate files before uploading:

from synapseclient import Synapse
from synapseclient.operations import md5_query
import hashlib

syn = Synapse()
syn.login()

# Calculate MD5 of a local file
def calculate_md5(file_path):
    hash_md5 = hashlib.md5()
    with open(file_path, "rb") as f:
        for chunk in iter(lambda: f.read(4096), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()

file_path = "/path/to/file.txt"
file_md5 = calculate_md5(file_path)

# Check if file already exists in Synapse
existing_entities = md5_query(file_md5)
if existing_entities:
    print(f"File already exists in Synapse:")
    for entity in existing_entities:
        print(f"- {entity['id']}: {entity['name']}")
else:
    print("File is unique, safe to upload")
Finding all versions of a file

Find all entities that share the same content (MD5):

from synapseclient import Synapse
from synapseclient.operations import md5_query, get

syn = Synapse()
syn.login()

# Get MD5 from a known file
file = get(synapse_id="syn123456")
if hasattr(file, 'file_handle') and file.file_handle:
    file_md5 = file.file_handle.content_md5

    # Find all entities with the same MD5
    matching_entities = md5_query(file_md5)
    print(f"Found {len(matching_entities)} entities with same content:")
    for entity in matching_entities:
        print(f"- {entity['id']}: {entity['name']} in {entity.get('parentId', 'unknown')}")
Source code in synapseclient/operations/utility_operations.py
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
def md5_query(
    md5: str,
    *,
    synapse_client: Optional["Synapse"] = None,
) -> List[dict]:
    """
    Find the Entities which have attached file(s) which have the given MD5 hash.

    Arguments:
        md5: The MD5 hash to query for (hexadecimal string).
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        A list of Entity headers matching the MD5 hash.

    Example: Finding entities by MD5 hash
        Search for entities with a specific MD5 hash:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import md5_query

        syn = Synapse()
        syn.login()

        md5_hash = "1234567890abcdef1234567890abcdef"
        results = md5_query(md5_hash)

        print(f"Found {len(results)} entities with MD5: {md5_hash}")
        for entity in results:
            print(f"- {entity['id']}: {entity['name']}")
        ```

    Example: Checking for duplicate files
        Use MD5 query to find duplicate files before uploading:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import md5_query
        import hashlib

        syn = Synapse()
        syn.login()

        # Calculate MD5 of a local file
        def calculate_md5(file_path):
            hash_md5 = hashlib.md5()
            with open(file_path, "rb") as f:
                for chunk in iter(lambda: f.read(4096), b""):
                    hash_md5.update(chunk)
            return hash_md5.hexdigest()

        file_path = "/path/to/file.txt"
        file_md5 = calculate_md5(file_path)

        # Check if file already exists in Synapse
        existing_entities = md5_query(file_md5)
        if existing_entities:
            print(f"File already exists in Synapse:")
            for entity in existing_entities:
                print(f"- {entity['id']}: {entity['name']}")
        else:
            print("File is unique, safe to upload")
        ```

    Example: Finding all versions of a file
        Find all entities that share the same content (MD5):

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import md5_query, get

        syn = Synapse()
        syn.login()

        # Get MD5 from a known file
        file = get(synapse_id="syn123456")
        if hasattr(file, 'file_handle') and file.file_handle:
            file_md5 = file.file_handle.content_md5

            # Find all entities with the same MD5
            matching_entities = md5_query(file_md5)
            print(f"Found {len(matching_entities)} entities with same content:")
            for entity in matching_entities:
                print(f"- {entity['id']}: {entity['name']} in {entity.get('parentId', 'unknown')}")
        ```
    """
    return wrap_async_to_sync(
        coroutine=md5_query_async(
            md5=md5,
            synapse_client=synapse_client,
        )
    )

synapseclient.operations.print_entity

print_entity(entity: Union[str, dict, Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable], ensure_ascii: bool = True, *, synapse_client: Optional[Synapse] = None) -> None

Pretty print an Entity as JSON.

PARAMETER DESCRIPTION
entity

Either an Entity object (Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable), a Synapse ID string, or a dictionary representation of an entity.

TYPE: Union[str, dict, Dataset, DatasetCollection, EntityView, File, Folder, Link, MaterializedView, Project, RecordSet, SubmissionView, Table, VirtualTable]

ensure_ascii

If True, escapes all non-ASCII characters in the output. Defaults to True.

TYPE: bool DEFAULT: True

synapse_client

If not passed in and caching was not disabled by Synapse.allow_client_caching(False) this will use the last created instance from the Synapse class constructor.

TYPE: Optional[Synapse] DEFAULT: None

RETURNS DESCRIPTION
None

None. Prints the entity to the logger.

Printing an entity by ID

Print an entity using its Synapse ID:

from synapseclient import Synapse
from synapseclient.operations import print_entity

syn = Synapse()
syn.login()

# Print entity by Synapse ID
print_entity("syn123456")
Printing an entity object

Print an entity object:

from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import print_entity, get

syn = Synapse()
syn.login()

# Get and print a file entity
file = get(synapse_id="syn123456")
print_entity(file)
Controlling ASCII output

Print an entity with non-ASCII characters:

from synapseclient import Synapse
from synapseclient.operations import print_entity

syn = Synapse()
syn.login()

# Print with unicode characters preserved
print_entity("syn123456", ensure_ascii=False)
Source code in synapseclient/operations/utility_operations.py
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
def print_entity(
    entity: Union[
        str,
        dict,
        "Dataset",
        "DatasetCollection",
        "EntityView",
        "File",
        "Folder",
        "Link",
        "MaterializedView",
        "Project",
        "RecordSet",
        "SubmissionView",
        "Table",
        "VirtualTable",
    ],
    ensure_ascii: bool = True,
    *,
    synapse_client: Optional["Synapse"] = None,
) -> None:
    """
    Pretty print an Entity as JSON.

    Arguments:
        entity: Either an Entity object (Dataset, DatasetCollection, EntityView,
            File, Folder, Link, MaterializedView, Project, RecordSet,
            SubmissionView, Table, VirtualTable), a Synapse ID string, or a
            dictionary representation of an entity.
        ensure_ascii: If True, escapes all non-ASCII characters in the output.
            Defaults to True.
        synapse_client: If not passed in and caching was not disabled by
            `Synapse.allow_client_caching(False)` this will use the last created
            instance from the Synapse class constructor.

    Returns:
        None. Prints the entity to the logger.

    Example: Printing an entity by ID
        Print an entity using its Synapse ID:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import print_entity

        syn = Synapse()
        syn.login()

        # Print entity by Synapse ID
        print_entity("syn123456")
        ```

    Example: Printing an entity object
        Print an entity object:

        ```python
        from synapseclient import Synapse
        from synapseclient.models import File
        from synapseclient.operations import print_entity, get

        syn = Synapse()
        syn.login()

        # Get and print a file entity
        file = get(synapse_id="syn123456")
        print_entity(file)
        ```

    Example: Controlling ASCII output
        Print an entity with non-ASCII characters:

        ```python
        from synapseclient import Synapse
        from synapseclient.operations import print_entity

        syn = Synapse()
        syn.login()

        # Print with unicode characters preserved
        print_entity("syn123456", ensure_ascii=False)
        ```
    """
    return wrap_async_to_sync(
        coroutine=print_entity_async(
            entity=entity,
            ensure_ascii=ensure_ascii,
            synapse_client=synapse_client,
        )
    )