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_async
async
¶
get_async(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:
- By providing a synapse_id directly
- 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. |
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. |
file_options
|
File-specific configuration options. Only applies to File entities. Ignored for other entity types.
TYPE:
|
link_options
|
Link-specific configuration options. Only applies when the entity is a Link. Ignored for other entity types.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| 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:
import asyncio
from synapseclient import Synapse
from synapseclient.models import File, Project
from synapseclient.operations import get_async
async def main():
syn = Synapse()
syn.login()
# Works for any entity type
entity = await get_async(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}")
asyncio.run(main())
Retrieving entities by name
Get an entity by name and parent:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async
async def main():
syn = Synapse()
syn.login()
# Get a file by name within a folder
entity = await get_async(
entity_name="my_file.txt",
parent_id="syn123456"
)
# Get a project by name (parent_id=None)
project = await get_async(
entity_name="My Project",
parent_id=None
)
asyncio.run(main())
Retrieving a specific version
Get a specific version of a versionable entity:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async
async def main():
syn = Synapse()
syn.login()
entity = await get_async(synapse_id="syn123456", version_number=2)
asyncio.run(main())
Retrieving a file with custom options
Get file metadata with specific download options:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, FileOptions, ActivityOptions
async def main():
syn = Synapse()
syn.login()
file_entity = await get_async(
synapse_id="syn123456",
activity_options=ActivityOptions(include_activity=True),
file_options=FileOptions(
download_file=False
)
)
asyncio.run(main())
Retrieving a table with activity and columns
Get table with activity and column information:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, ActivityOptions, TableOptions
async def main():
syn = Synapse()
syn.login()
table_entity = await get_async(
synapse_id="syn123456",
activity_options=ActivityOptions(include_activity=True),
table_options=TableOptions(include_columns=True)
)
asyncio.run(main())
Following links
Get the target of a link entity:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, LinkOptions
async def main():
syn = Synapse()
syn.login()
target_entity = await get_async(
synapse_id="syn123456",
link_options=LinkOptions(follow_link=True)
)
asyncio.run(main())
Working with Link entities
Get a Link entity without following it:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, LinkOptions
async def main():
syn = Synapse()
syn.login()
# Get the link entity itself
link_entity = await get_async(
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 = await get_async(
synapse_id="syn123456",
link_options=LinkOptions(follow_link=True)
)
print(f"Target: {target_entity.name} (type: {type(target_entity).__name__})")
asyncio.run(main())
Comprehensive File options
Download file with custom location and collision handling:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, FileOptions
async def main():
syn = Synapse()
syn.login()
file_entity = await get_async(
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}")
asyncio.run(main())
Table options for table-like entities
Get table entities with column information:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, TableOptions
async def main():
syn = Synapse()
syn.login()
# Works for Table, Dataset, EntityView, MaterializedView,
# SubmissionView, VirtualTable, and DatasetCollection
table_entity = await get_async(
synapse_id="syn123456", # Example table ID
table_options=TableOptions(include_columns=True)
)
print(f"Table: {table_entity.name} with {len(table_entity.columns)} columns")
asyncio.run(main())
Combining multiple options
Get a File with both activity and custom download options:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, FileOptions, ActivityOptions
async def main():
syn = Synapse()
syn.login()
file_entity = await get_async(
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})")
asyncio.run(main())
Working with entity instances
Pass an existing entity instance to refresh or apply new options:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import get_async, FileOptions
async def main():
syn = Synapse()
syn.login()
# Get an entity first
entity = await get_async(synapse_id="syn123456")
print(f"Original entity: {entity.name}")
# Then use the entity instance to get it again with different options
refreshed_entity = await get_async(
entity,
file_options=FileOptions(download_file=False)
)
print(f"Refreshed entity: {refreshed_entity.name} (download_file: {refreshed_entity.download_file})")
asyncio.run(main())
Source code in synapseclient/operations/factory_operations.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 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 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | |
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:
|
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".
TYPE:
|
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 | |
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:
|
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 | |
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:
|
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 | |
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:
|
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 | |
synapseclient.operations.delete_async
async
¶
delete_async(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 asynchronously.
This method serves as a unified interface for deleting any type of Synapse entity asynchronously. 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:
-
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.
-
Entity's version_number attribute (secondary): If the entity object has a
version_numberattribute set and no explicitversionparameter is provided, this version will be used. -
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
versionparameter or the entity'sversion_numberattribute.
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:
|
version
|
Optional version number to delete. Takes precedence over any version
information in the entity object or ID string. When provided with
|
version_only
|
If True, only the specified version will be deleted, not the
entire entity. Requires a version number from either the
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| 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:
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import delete_async
async def main():
syn = Synapse()
syn.login()
file = File(id="syn123456")
await delete_async(file)
print("File deleted successfully")
asyncio.run(main())
Deleting a specific version of a file
Delete only version 2 of a file, keeping other versions:
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import delete_async
async def main():
syn = Synapse()
syn.login()
# Method 1: Using version parameter (highest priority)
file = File(id="syn123456")
await delete_async(file, version=2, version_only=True)
# Method 2: Using entity's version_number attribute
file = File(id="syn123456", version_number=2)
await delete_async(file, version_only=True)
# Method 3: Using synapse ID with version
await delete_async("syn123456.2", version_only=True)
print("File version 2 deleted successfully")
asyncio.run(main())
Deleting a file by ID string
Delete a file from Synapse using just its ID:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import delete_async
async def main():
syn = Synapse()
syn.login()
await delete_async("syn123456")
print("Entity deleted successfully")
asyncio.run(main())
Deleting a specific version of a RecordSet
Delete only a specific version of a RecordSet:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
from synapseclient.operations import delete_async
async def main():
syn = Synapse()
syn.login()
record_set = RecordSet(id="syn123456", version_number=3)
await delete_async(record_set, version_only=True)
print("RecordSet version 3 deleted successfully")
asyncio.run(main())
Source code in synapseclient/operations/delete_operations.py
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 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 | |
synapseclient.operations.store_async
async
¶
store_async(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 asynchronously.
This method serves as a unified interface for storing any type of Synapse entity asynchronously. 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:
|
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.
TYPE:
|
container_options
|
Container-specific configuration options. Only applies to Project and Folder entities. Ignored for other entity types.
TYPE:
|
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:
|
json_schema_options
|
JSONSchema-specific configuration options. Only applies to JSONSchema entities. Required for JSONSchema. Ignored for other entity types.
TYPE:
|
grid_options
|
Grid-specific configuration options. Only applies to Grid entities. Ignored for other entity types.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| 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:
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import store_async
async def main():
syn = Synapse()
syn.login()
file = File(path="/path/to/file.txt", parent_id="syn123456")
stored_file = await store_async(file)
print(f"Stored file: {stored_file.name} (ID: {stored_file.id})")
asyncio.run(main())
Storing a file with custom options
Store a file with custom options:
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import store_async, StoreFileOptions
async def main():
syn = Synapse()
syn.login()
file = File(path="/path/to/file.txt", parent_id="syn123456")
stored_file = await store_async(
file,
file_options=StoreFileOptions(
synapse_store=True,
content_type="text/plain",
merge_existing_annotations=True
)
)
print(f"Stored file: {stored_file.name}")
asyncio.run(main())
Storing a folder
Store a folder to Synapse:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Folder
from synapseclient.operations import store_async
async def main():
syn = Synapse()
syn.login()
folder = Folder(name="My Folder", parent_id="syn123456")
stored_folder = await store_async(folder)
print(f"Stored folder: {stored_folder.name} (ID: {stored_folder.id})")
asyncio.run(main())
Storing a project
Store a project to Synapse:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Project
from synapseclient.operations import store_async
async def main():
syn = Synapse()
syn.login()
project = Project(name="My Project")
stored_project = await store_async(project)
print(f"Stored project: {stored_project.name} (ID: {stored_project.id})")
asyncio.run(main())
Storing a table
Store a table to Synapse:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Table, Column, ColumnType
from synapseclient.operations import store_async, StoreTableOptions
async def main():
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 = await store_async(
table,
table_options=StoreTableOptions(dry_run=False, job_timeout=600)
)
print(f"Stored table: {stored_table.name} (ID: {stored_table.id})")
asyncio.run(main())
Storing a link
Store a link to Synapse:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Link
from synapseclient.operations import store_async
async def main():
syn = Synapse()
syn.login()
link = Link(name="My Link", parent_id="syn123456", target_id="syn789")
stored_link = await store_async(link)
print(f"Stored link: {stored_link.name} (ID: {stored_link.id})")
asyncio.run(main())
Storing with parent parameter
Store an entity by passing the parent as a parameter:
import asyncio
from synapseclient import Synapse
from synapseclient.models import File, Folder
from synapseclient.operations import store_async
async def main():
syn = Synapse()
syn.login()
parent_folder = Folder(id="syn123456")
file = File(path="/path/to/file.txt")
stored_file = await store_async(file, parent=parent_folder)
print(f"Stored file: {stored_file.name} in folder {parent_folder.id}")
asyncio.run(main())
Source code in synapseclient/operations/store_operations.py
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 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 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 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 | |
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. |
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. |
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 | |
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:
|
Source code in synapseclient/operations/store_operations.py
55 56 57 58 59 60 61 62 63 64 65 66 | |
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:
|
job_timeout |
Maximum time to wait for table schema update job to complete.
TYPE:
|
Source code in synapseclient/operations/store_operations.py
69 70 71 72 73 74 75 76 77 78 79 | |
synapseclient.operations.StoreJSONSchemaOptions
dataclass
¶
Options for storing JSONSchema entities.
| ATTRIBUTE | DESCRIPTION |
|---|---|
schema_body |
The body of the JSONSchema to store.
TYPE:
|
version |
The version of the JSONSchema body to store. |
dry_run |
Whether or not to do a dry-run.
TYPE:
|
Source code in synapseclient/operations/store_operations.py
82 83 84 85 86 87 88 89 90 91 92 93 94 | |
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:
|
timeout |
The number of seconds to wait for the job to complete.
TYPE:
|
Source code in synapseclient/operations/store_operations.py
97 98 99 100 101 102 103 104 105 106 107 108 | |
synapseclient.operations.find_entity_id_async
async
¶
find_entity_id_async(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 asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the entity to find.
TYPE:
|
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:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
The Entity ID or None if not found. |
Finding a project by name
Find a project using only its name:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import find_entity_id_async
async def main():
syn = Synapse()
syn.login()
project_id = await find_entity_id_async(name="My Project")
if project_id:
print(f"Found project: {project_id}")
else:
print("Project not found")
asyncio.run(main())
Finding an entity within a parent
Find a file within a specific folder:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import find_entity_id_async
async def main():
syn = Synapse()
syn.login()
file_id = await find_entity_id_async(
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")
asyncio.run(main())
Source code in synapseclient/operations/utility_operations.py
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 | |
synapseclient.operations.is_synapse_id_async
async
¶
Check if given synID is valid (attached to actual entity) asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
syn_id
|
A Synapse ID to validate.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the Synapse ID is valid. |
Validating a Synapse ID
Check if a Synapse ID exists:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import is_synapse_id_async
async def main():
syn = Synapse()
syn.login()
if await is_synapse_id_async("syn123456"):
print("Valid Synapse ID")
else:
print("Invalid or non-existent Synapse ID")
asyncio.run(main())
Validating multiple IDs concurrently
Check multiple Synapse IDs concurrently:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import is_synapse_id_async
async def main():
syn = Synapse()
syn.login()
ids_to_check = ["syn123456", "syn999999", "syn789012"]
results = await asyncio.gather(
*[is_synapse_id_async(synapse_id) for synapse_id in ids_to_check]
)
for synapse_id, is_valid in zip(ids_to_check, results):
if is_valid:
print(f"{synapse_id} is valid")
else:
print(f"{synapse_id} is invalid or does not exist")
asyncio.run(main())
Source code in synapseclient/operations/utility_operations.py
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 | |
synapseclient.operations.onweb_async
async
¶
onweb_async(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 asynchronously.
| 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:
|
subpage_id
|
(Optional) ID of one of the wiki's sub-pages. |
synapse_client
|
If not passed in and caching was not disabled by
|
| 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:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import onweb_async
async def main():
syn = Synapse()
syn.login()
# Open by Synapse ID
url = await onweb_async("syn123456")
print(f"Opened: {url}")
asyncio.run(main())
Opening with an entity object
Open an entity using an entity object:
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
from synapseclient.operations import onweb_async, get_async
async def main():
syn = Synapse()
syn.login()
file = await get_async(synapse_id="syn123456")
url = await onweb_async(file)
print(f"Opened file: {url}")
asyncio.run(main())
Source code in synapseclient/operations/utility_operations.py
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 | |
synapseclient.operations.md5_query_async
async
¶
Find the Entities which have attached file(s) which have the given MD5 hash asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
md5
|
The MD5 hash to query for (hexadecimal string).
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| 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:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import md5_query_async
async def main():
syn = Synapse()
syn.login()
md5_hash = "1234567890abcdef1234567890abcdef"
results = await md5_query_async(md5_hash)
print(f"Found {len(results)} entities with MD5: {md5_hash}")
for entity in results:
print(f"- {entity['id']}: {entity['name']}")
asyncio.run(main())
Checking multiple MD5 hashes concurrently
Query multiple MD5 hashes at the same time:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import md5_query_async
async def main():
syn = Synapse()
syn.login()
md5_hashes = [
"1234567890abcdef1234567890abcdef",
"abcdef1234567890abcdef1234567890",
"567890abcdef1234567890abcdef1234"
]
# Query all MD5 hashes concurrently
results = await asyncio.gather(
*[md5_query_async(md5) for md5 in md5_hashes]
)
for md5, entities in zip(md5_hashes, results):
print(f"MD5 {md5}: {len(entities)} matching entities")
asyncio.run(main())
Source code in synapseclient/operations/utility_operations.py
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 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
synapseclient.operations.print_entity_async
async
¶
print_entity_async(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 asynchronously.
| 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:
|
ensure_ascii
|
If True, escapes all non-ASCII characters in the output. Defaults to True.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None. Prints the entity to the logger. |
Printing an entity by ID
Print an entity using its Synapse ID:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import print_entity_async
async def main():
syn = Synapse()
syn.login()
# Print entity by Synapse ID
await print_entity_async("syn123456")
asyncio.run(main())
Printing multiple entities concurrently
Print multiple entities at the same time:
import asyncio
from synapseclient import Synapse
from synapseclient.operations import print_entity_async
async def main():
syn = Synapse()
syn.login()
entity_ids = ["syn123456", "syn789012", "syn345678"]
# Print all entities concurrently
await asyncio.gather(
*[print_entity_async(entity_id) for entity_id in entity_ids]
)
asyncio.run(main())
Source code in synapseclient/operations/utility_operations.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 | |