Curator¶
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.models.CurationTask
dataclass
¶
Bases: CurationTaskSynchronousProtocol
The CurationTask provides instructions for a Data Contributor on how data or metadata of a specific type should be both added to a project and curated.
Represents a Synapse CurationTask.
| ATTRIBUTE | DESCRIPTION |
|---|---|
task_id |
The unique identifier issued to this task when it was created |
data_type |
Will match the data type that a contributor plans to contribute |
project_id |
The synId of the project |
instructions |
Instructions to the data contributor |
task_properties |
The properties of a CurationTask. This can be either FileBasedMetadataTaskProperties or RecordBasedMetadataTaskProperties.
TYPE:
|
etag |
Synapse employs an Optimistic Concurrency Control (OCC) scheme to handle concurrent updates. Since the E-Tag changes every time an entity is updated it is used to detect when a client's current representation of an entity is out-of-date. |
created_on |
(Read Only) The date this task was created |
modified_on |
(Read Only) The date this task was last modified |
created_by |
(Read Only) The ID of the user that created this task |
modified_by |
(Read Only) The ID of the user that last modified this task |
Complete curation task workflow
from synapseclient import Synapse
from synapseclient.models import CurationTask, FileBasedMetadataTaskProperties
syn = Synapse()
syn.login()
# Create a new file-based curation task
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 and complete metadata",
task_properties=file_properties
)
task = task.store()
print(f"Created task: {task.task_id}")
# Later, retrieve and update the task
existing_task = CurationTask(task_id=task.task_id).get()
existing_task.instructions = "Updated instructions with new requirements"
existing_task.store()
# List all tasks in the project
for project_task in CurationTask.list(project_id="syn9876543"):
print(f"Task: {project_task.data_type} - {project_task.task_id}")
Source code in synapseclient/models/curation.py
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 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 | |
Methods:¶
get_async
async
¶
get_async(*, synapse_client: Optional[Synapse] = None) -> CurationTask
Gets a CurationTask from Synapse by ID.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
CurationTask
|
The CurationTask object.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the CurationTask object does not have a task_id. |
ValueError
|
If the Synapse response does not contain taskProperties. |
Get a curation task asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
task = await CurationTask(task_id=123).get_async()
print(f"Data type: {task.data_type}")
print(f"Instructions: {task.instructions}")
asyncio.run(main())
Source code in synapseclient/models/curation.py
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 | |
get_status_async
async
¶
get_status_async(*, synapse_client: Synapse | None = None) -> CurationTaskStatus
Gets the status of this CurationTask from Synapse.
| PARAMETER | DESCRIPTION |
|---|---|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
CurationTaskStatus
|
The CurationTaskStatus object. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the CurationTask object does not have a task_id. |
Get the status of a curation task asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
status = await CurationTask(task_id=123).get_status_async()
print(status.state)
asyncio.run(main())
Source code in synapseclient/models/curation.py
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 | |
update_status_async
async
¶
update_status_async(curation_task_status: CurationTaskStatus, *, synapse_client: Synapse | None = None) -> CurationTaskStatus
Updates the status of this CurationTask on Synapse.
| PARAMETER | DESCRIPTION |
|---|---|
curation_task_status
|
The complete CurationTaskStatus object to update.
TYPE:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
CurationTaskStatus
|
The updated CurationTaskStatus object. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the CurationTask object does not have a task_id. |
Update the status of a curation task asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import (
CurationTask,
TaskState,
)
syn = Synapse()
syn.login()
async def main():
task = CurationTask(task_id=123)
current = await task.get_status_async()
current.state = TaskState.COMPLETED
updated = await task.update_status_async(curation_task_status=current)
print(updated.state)
asyncio.run(main())
Source code in synapseclient/models/curation.py
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 | |
set_active_grid_session_async
async
¶
set_active_grid_session_async(active_session_id: str, *, synapse_client: Synapse | None = None) -> CurationTaskStatus
Set the active grid session on this CurationTask's status by replacing execution_details with a GridExecutionDetails carrying the given session id.
| PARAMETER | DESCRIPTION |
|---|---|
active_session_id
|
The unique identifier of the active grid session to link.
TYPE:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
CurationTaskStatus
|
The updated CurationTaskStatus object. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the CurationTask object does not have a task_id. |
Link a grid session to a curation task asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask, Grid
syn = Synapse()
syn.login()
async def main():
grid = await Grid(record_set_id="syn1234567").create_async()
await CurationTask(task_id=123).set_active_grid_session_async(
active_session_id=grid.session_id
)
asyncio.run(main())
Source code in synapseclient/models/curation.py
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 | |
delete_async
async
¶
Deletes a CurationTask from Synapse.
| PARAMETER | DESCRIPTION |
|---|---|
delete_source
|
If True, the associated source data (EntityView or RecordSet) will also be deleted if the task is a FileBasedMetadataTask or RecordBasedMetadataTask respectively. Defaults to False.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the CurationTask object does not have a task_id. |
ValueError
|
If delete_source is True but the task properties are not properly set to identify the source to delete. |
Delete a curation task asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
task = CurationTask(task_id=123)
await task.delete_async()
print("Task deleted successfully")
asyncio.run(main())
Delete a curation task and its associated data source asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
task = CurationTask(task_id=123)
await task.delete_async(delete_source=True)
print("Task and record set deleted successfully")
asyncio.run(main())
Source code in synapseclient/models/curation.py
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 | |
store_async
async
¶
store_async(*, synapse_client: Optional[Synapse] = None) -> CurationTask
Creates a new CurationTask or updates an existing one on Synapse.
This method implements non-destructive updates. If a CurationTask with the same project_id and data_type exists and this instance hasn't been retrieved from Synapse before, it will merge the existing task data with the current instance before updating.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
CurationTask
|
The CurationTask object.
TYPE:
|
Create a new curation task asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask, FileBasedMetadataTaskProperties
syn = Synapse()
syn.login()
async def main():
# Create file-based task properties
file_properties = FileBasedMetadataTaskProperties(
upload_folder_id="syn1234567",
file_view_id="syn2345678"
)
# Create and store the curation task
task = CurationTask(
project_id="syn9876543",
data_type="genomics_data",
instructions="Upload your genomics files to the specified folder",
task_properties=file_properties
)
task = await task.store_async()
print(f"Created task with ID: {task.task_id}")
asyncio.run(main())
Source code in synapseclient/models/curation.py
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 | |
list_async
async
classmethod
¶
list_async(project_id: str, *, assigned_to_me: Optional[bool] = None, assignee_ids: Optional[list[str]] = None, state_filter: Optional[list[Union[TaskState, str]]] = None, synapse_client: Optional[Synapse] = None) -> AsyncGenerator[CurationTask, None]
Generator that yields CurationTasks for a project as they become available.
| PARAMETER | DESCRIPTION |
|---|---|
project_id
|
The synId of the project.
TYPE:
|
assigned_to_me
|
When True, only return tasks assigned to the current user. Cannot be combined with assignee_ids. False does not mean "tasks not assigned to me". Defaults to None. |
assignee_ids
|
Optional list of principal IDs (users or teams) to filter tasks by assignee. Cannot be combined with assigned_to_me=True. Passing an empty list raises a ValueError; pass None to return tasks for any assignee. Defaults to None. |
state_filter
|
Optional list of TaskState values or exact-case strings to filter tasks by their current state (e.g., "IN_PROGRESS"). Defaults to None (all states returned). Passing an empty list raises a ValueError; pass None to return tasks in any state. |
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. |
| YIELDS | DESCRIPTION |
|---|---|
AsyncGenerator[CurationTask, None]
|
CurationTask objects as they are retrieved from the API. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If state_filter is an empty list. |
ValueError
|
If assignee_ids is an empty list. |
ValueError
|
If assigned_to_me is True and assignee_ids is also provided. |
ValueError
|
If any value in state_filter is not a TaskState member or an exact-case string matching a TaskState value (e.g., "IN_PROGRESS"). |
ValueError
|
If the Synapse response for any task does not contain taskProperties. |
List all curation tasks in a project asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
# List all curation tasks in the project
async for task in CurationTask.list_async(project_id="syn9876543"):
print(f"Task ID: {task.task_id}")
print(f"Data Type: {task.data_type}")
print(f"Instructions: {task.instructions}")
print("---")
asyncio.run(main())
List only curation tasks assigned to the current user asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
async for task in CurationTask.list_async(
project_id="syn9876543", assigned_to_me=True
):
print(f"Task ID: {task.task_id}")
print(f"Data Type: {task.data_type}")
print("---")
asyncio.run(main())
List only in-progress curation tasks asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask, TaskState
syn = Synapse()
syn.login()
async def main():
async for task in CurationTask.list_async(
project_id="syn9876543",
state_filter=[TaskState.IN_PROGRESS],
):
print(f"Task ID: {task.task_id}")
print(f"Data Type: {task.data_type}")
print("---")
asyncio.run(main())
List only in-progress curation tasks using a string state filter asynchronously
state_filter also accepts plain strings matching TaskState names exactly.
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
async for task in CurationTask.list_async(
project_id="syn9876543",
state_filter=["IN_PROGRESS"],
):
print(f"Task ID: {task.task_id}")
print(f"Data Type: {task.data_type}")
print("---")
asyncio.run(main())
Source code in synapseclient/models/curation.py
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 | |
create_grid_session_async
async
¶
create_grid_session_async(*, owner_principal_id: int | None = None, timeout: int = 120, synapse_client: Synapse | None = None) -> Grid
Create a new Grid session for this CurationTask and set it as the active session.
Picks the Grid seed from this task's task_properties:
- RecordBasedMetadataTaskProperties uses record_set_id
- FileBasedMetadataTaskProperties uses an initial_query that selects from the file_view_id
Always creates a new Grid session. To attach an existing session to a task, use set_active_grid_session_async instead.
After the Grid is created, updates the CurationTaskStatus to point its active_session_id at the new session. If that update fails for any reason, the newly created Grid is deleted on a best-effort basis and the original exception is re-raised.
| PARAMETER | DESCRIPTION |
|---|---|
owner_principal_id
|
The principal ID (user or team) that will own the created grid session. When not provided, the principal ID of the caller is used.
TYPE:
|
timeout
|
Seconds to wait for the grid creation job. Defaults to 120.
TYPE:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
Grid
|
The newly created Grid. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If task_id is unset or task_properties is of an unsupported type. |
SynapseHTTPError
|
If the RecordSet or EntityView does not exist, or if the status update fails. The orphan Grid is deleted on a best-effort basis before the error is re-raised. |
Create a grid session for a curation task asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
grid = await CurationTask(task_id=123).create_grid_session_async()
print(grid.session_id)
asyncio.run(main())
Source code in synapseclient/models/curation.py
1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 | |
set_task_state_async
async
¶
set_task_state_async(state: TaskState | str, *, synapse_client: Synapse | None = None) -> CurationTaskStatus
Set the state on this CurationTask's status.
Does not modify execution_details. Fetches the current CurationTaskStatus first so the update carries a fresh etag.
| PARAMETER | DESCRIPTION |
|---|---|
state
|
The state to set on this task's status. Accepts a TaskState or a string exactly matching one of its members (e.g. NOT_STARTED, IN_PROGRESS, COMPLETED, CANCELED).
TYPE:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
CurationTaskStatus
|
The updated CurationTaskStatus object. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the CurationTask object does not have a task_id, or if state is a string that does not match a TaskState member. |
Mark a curation task as completed asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask, TaskState
syn = Synapse()
syn.login()
async def main():
await CurationTask(task_id=123).set_task_state_async(
state=TaskState.COMPLETED
)
asyncio.run(main())
Mark a curation task as completed using a string asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import CurationTask
syn = Synapse()
syn.login()
async def main():
await CurationTask(task_id=123).set_task_state_async(
state="COMPLETED"
)
asyncio.run(main())
Source code in synapseclient/models/curation.py
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 | |
synapseclient.models.RecordSet
dataclass
¶
Bases: RecordSetSynchronousProtocol, AccessControllable, BaseJSONSchema
A RecordSet entity captures record-based metadata as a special type of CSV. The record set content can be curated using the grid services. When a grid is created from a record set, its data can be exported back to a new version of the record set. The export will include the validation summary as well as a validation file handle that contains detailed validation results for each row in the record set.
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
The unique immutable ID for this file. A new ID will be generated for new Files. Once issued, this ID is guaranteed to never change or be re-issued. |
name |
The name of this entity. Must be 256 characters or less. Names may only contain: letters, numbers, spaces, underscores, hyphens, periods, plus signs, apostrophes, and parentheses. If not specified, the name will be derived from the file name. |
path |
The path to the file on disk. Using shorthand This is used during a This is also used during a |
description |
The description of this file. Must be 1000 characters or less. |
parent_id |
The ID of the Entity that is the parent of this Entity. Setting this to a new value and storing it will move this File under the new parent. |
version_label |
The version label for this entity. Updates to the entity will increment the version number. |
version_comment |
The version comment for this entity. |
data_file_handle_id |
ID of the file handle associated with this entity. You may define an existing data_file_handle_id to use the existing data_file_handle_id. The creator of the file must also be the owner of the data_file_handle_id to have permission to store the file. |
activity |
The Activity model represents the main record of Provenance in Synapse. It is analygous to the Activity defined in the W3C Specification on Provenance. Activity cannot be removed during a store operation by setting it to None. You must use: synapseclient.models.Activity.delete_async or synapseclient.models.Activity.disassociate_from_entity_async. |
annotations |
Additional metadata associated with the entity. The key is the
name of your desired annotations. The value is an object containing a list
of values (use empty list to represent no values for key) and the value
type associated with all values in the list. To remove all annotations
set this to an empty dict
TYPE:
|
upsert_keys |
One or more column names that define this upsert key for this set. This key is used to determine if a new record should be treated as an update or an insert. |
csv_descriptor |
The description of a CSV for upload or download.
TYPE:
|
validation_summary |
Summary statistics for the JSON schema validation results for the children of an Entity container (Project or Folder).
TYPE:
|
file_name_override |
An optional replacement for the name of the uploaded file. This is distinct from the entity name. If omitted the file will retain its original name. |
validation_file_handle_id |
(Read Only) Pointer to a CSV file that contains the detailed validation results for each row in the record set. The CSV file will contain for each row the following columns: row_index, is_valid, validation_error_message, all_validation_messages. Generated only from a grid session export, cannot be changed by the user. |
content_type |
(New Upload Only) Used to manually specify Content-type header, for example 'application/png' or 'application/json; charset=UTF-8'. If not specified, the content type will be derived from the file extension. This can be specified only during the initial store of this file. In order to change this after the File has been created use synapseclient.models.File.change_metadata. |
content_size |
(New Upload Only) The size of the file in bytes. This can be
specified only during the initial creation of the File. This is also only
applicable to files not uploaded to Synapse. ie: |
content_md5 |
(Store only) The MD5 of the file is known. If not supplied this
will be computed in the client is possible. If supplied for a file entity
already stored in Synapse it will be calculated again to check if a new
upload needs to occur. This will not be filled in during a read for data.
It is only used during a store operation. To retrieve the md5 of the file
after read from synapse use the |
create_or_update |
(Store only) Indicates whether the method should automatically perform an update if the file conflicts with an existing Synapse object.
TYPE:
|
force_version |
(Store only) Indicates whether the method should increment the version of the object if something within the entity has changed. For example updating the description or name. You may set this to False and an update to the entity will not increment the version. Updating the An update to the MD5 of the file will force a version update regardless of this flag.
TYPE:
|
is_restricted |
(Store only) If set to true, an email will be sent to the Synapse access control team to start the process of adding terms-of-use or review board approval for this entity. You will be contacted with regards to the specific data being restricted and the requirements of access. This may be used only by an administrator of the specified file.
TYPE:
|
merge_existing_annotations |
(Store only) Works in conjunction with
TYPE:
|
associate_activity_to_new_version |
(Store only) Works in conjunction with
When this is False the activity will not be associated to the new version of the entity during a store operation. Regardless of this setting, if you have an Activity object on the entity it will be persisted onto the new version. This is only used when you don't have an Activity object on the entity.
TYPE:
|
synapse_store |
(Store only) Whether the File should be uploaded or if false: only the path should be stored when synapseclient.models.File.store is called.
TYPE:
|
download_file |
(Get only) If True the file will be downloaded.
TYPE:
|
if_collision |
(Get only) Determines how to handle file collisions. Defaults to "keep.both". May be:
TYPE:
|
synapse_container_limit |
(Get only) A Synanpse ID used to limit the search in Synapse if file is specified as a local file. That is, if the file is stored in multiple locations in Synapse only the ones in the specified folder/project will be returned. |
etag |
(Read Only) Synapse employs an Optimistic Concurrency Control (OCC) scheme to handle concurrent updates. Since the E-Tag changes every time an entity is updated it is used to detect when a client's current representation of an entity is out-of-date. |
created_on |
(Read Only) The date this entity was created. |
modified_on |
(Read Only) The date this entity was last modified. |
created_by |
(Read Only) The ID of the user that created this entity. |
modified_by |
(Read Only) The ID of the user that last modified this entity. |
version_number |
(Read Only) The version number issued to this version on the object. |
is_latest_version |
(Read Only) If this is the latest version of the object. |
file_handle |
(Read Only) The file handle associated with this entity.
TYPE:
|
Source code in synapseclient/models/recordset.py
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 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 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 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 | |
Methods:¶
get_async
async
¶
Get the RecordSet from Synapse.
This method retrieves a RecordSet entity from Synapse. You may retrieve a RecordSet by either its ID or path. If you specify both, the ID will take precedence.
If you specify the path and the RecordSet is stored in multiple locations in Synapse, only the first one found will be returned. The other matching RecordSets will be printed to the console.
You may also specify a version_number to get a specific version of the
RecordSet.
| PARAMETER | DESCRIPTION |
|---|---|
include_activity
|
If True, the activity will be included in the RecordSet if it exists.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
RecordSet
|
The RecordSet object with data populated from Synapse. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the RecordSet does not have an ID or path to retrieve. |
Retrieving a RecordSet by ID
Get an existing RecordSet from Synapse:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
async def main():
syn = Synapse()
syn.login()
record_set = await RecordSet(id="syn123").get_async()
print(f"RecordSet name: {record_set.name}")
asyncio.run(main())
Downloading a RecordSet to a specific directory:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
async def main():
syn = Synapse()
syn.login()
record_set = await RecordSet(
id="syn123",
path="/path/to/download/directory"
).get_async()
asyncio.run(main())
Including activity information:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
async def main():
syn = Synapse()
syn.login()
record_set = await RecordSet(id="syn123").get_async(include_activity=True)
if record_set.activity:
print(f"Activity: {record_set.activity.name}")
asyncio.run(main())
Source code in synapseclient/models/recordset.py
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 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 | |
store_async
async
¶
store_async(parent: Optional[Union[Folder, Project]] = None, *, synapse_client: Optional[Synapse] = None) -> RecordSet
Store the RecordSet in Synapse.
This method uploads or updates a RecordSet in Synapse. It can handle both
creating new RecordSets and updating existing ones based on the
create_or_update flag. The method supports file uploads, metadata updates,
and merging with existing entities when appropriate.
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent Folder or Project for this RecordSet. If provided,
this will override the |
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
RecordSet
|
The RecordSet object with updated metadata from Synapse after the |
RecordSet
|
store operation. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the RecordSet does not have the required information for storing. Must have either: (ID with path or data_file_handle_id), or (path with parent_id), or (data_file_handle_id with parent_id). |
Storing a new RecordSet
Creating and storing a new RecordSet in Synapse:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
async def main():
syn = Synapse()
syn.login()
record_set = RecordSet(
name="My RecordSet",
description="A dataset for analysis",
parent_id="syn123456",
path="/path/to/data.csv"
)
stored_record_set = await record_set.store_async()
print(f"Stored RecordSet with ID: {stored_record_set.id}")
asyncio.run(main())
Updating an existing RecordSet:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
async def main():
syn = Synapse()
syn.login()
record_set = await RecordSet(id="syn789012").get_async()
record_set.description = "Updated description"
updated_record_set = await record_set.store_async()
asyncio.run(main())
Source code in synapseclient/models/recordset.py
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 | |
delete_async
async
¶
delete_async(version_only: Optional[bool] = False, *, synapse_client: Optional[Synapse] = None) -> None
Delete the RecordSet from Synapse using its ID.
This method removes a RecordSet entity from Synapse. You can choose to delete either a specific version or the entire RecordSet including all its versions.
| PARAMETER | DESCRIPTION |
|---|---|
version_only
|
If True, only the version specified in the |
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the RecordSet does not have an ID to delete. |
ValueError
|
If the RecordSet does not have a version number to delete a
specific version, and |
Deleting a RecordSet
Delete an entire RecordSet and all its versions:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
async def main():
syn = Synapse()
syn.login()
await RecordSet(id="syn123").delete_async()
asyncio.run(main())
Delete only a specific version:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet
async def main():
syn = Synapse()
syn.login()
record_set = RecordSet(id="syn123", version_number=2)
await record_set.delete_async(version_only=True)
asyncio.run(main())
Source code in synapseclient/models/recordset.py
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 | |
get_detailed_validation_results_async
async
¶
get_detailed_validation_results_async(download_location: Optional[str] = None, *, synapse_client: Optional[Synapse] = None) -> DataFrame
Get detailed validation results for the RecordSet as a pandas DataFrame.
This method downloads a CSV file containing detailed validation results for each row in the RecordSet. The validation results are generated when a RecordSet with a bound JSON schema is exported from a Grid session. The CSV contains columns: - row_index: The index of the row in the RecordSet - is_valid: Boolean indicating if the row is valid according to the schema - validation_error_message: The primary validation error message (if any) - all_validation_messages: All validation messages for the row (if any)
| PARAMETER | DESCRIPTION |
|---|---|
download_location
|
Optional directory path where the validation results CSV should be downloaded. If not specified, the file will be downloaded to the Synapse cache directory. If the file is already cached, it will use the cached version unless a different download_location is specified. |
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A pandas DataFrame containing the validation results, or None if no |
DataFrame
|
validation_file_handle_id is available (with a warning logged). |
Get validation results for a RecordSet
Get detailed validation results after exporting from a Grid session:
import asyncio
from synapseclient import Synapse
from synapseclient.models import RecordSet, Grid
async def main():
syn = Synapse()
syn.login()
# Assuming you have a RecordSet with a bound schema
record_set = await RecordSet(id="syn123").get_async()
# Create and export Grid session to generate validation results
grid = await Grid(record_set_id=record_set.id).create_async()
await grid.export_to_record_set_async()
await grid.delete_async()
# Re-fetch the RecordSet to get updated validation_file_handle_id
record_set = await record_set.get_async()
# Get the detailed validation results
results_df = await record_set.get_detailed_validation_results_async()
# Analyze the results
print(f"Total rows: {len(results_df)}")
print(f"Columns: {results_df.columns.tolist()}")
# Filter for valid and invalid rows
# Note: is_valid is boolean (True/False) for validated rows
valid_rows = results_df[results_df['is_valid'] == True] # noqa: E712
invalid_rows = results_df[results_df['is_valid'] == False] # noqa: E712
print(f"Valid rows: {len(valid_rows)}")
print(f"Invalid rows: {len(invalid_rows)}")
# View invalid rows with their error messages
if len(invalid_rows) > 0:
print(invalid_rows[['row_index', 'validation_error_message']])
asyncio.run(main())
Source code in synapseclient/models/recordset.py
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 | |
get_acl_async
async
¶
get_acl_async(principal_id: int = None, check_benefactor: bool = True, *, synapse_client: Optional[Synapse] = None) -> List[str]
Get the ACL that a user or group has on an Entity.
Note: If the entity does not have local sharing settings, or ACL set directly on it, this will look up the ACL on the benefactor of the entity. The benefactor is the entity that the current entity inherits its permissions from. The benefactor is usually the parent entity, but it can be any ancestor in the hierarchy. For example, a newly created Project will be its own benefactor, while a new FileEntity's benefactor will start off as its containing Project or Folder. If the entity already has local sharing settings, the benefactor would be itself.
| PARAMETER | DESCRIPTION |
|---|---|
principal_id
|
Identifier of a user or group (defaults to PUBLIC users)
TYPE:
|
check_benefactor
|
If True (default), check the benefactor for the entity to get the ACL. If False, only check the entity itself. This is useful for checking the ACL of an entity that has local sharing settings, but you want to check the ACL of the entity itself and not the benefactor it may inherit from.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
An array containing some combination of ['READ', 'UPDATE', 'CREATE', 'DELETE', 'DOWNLOAD', 'MODERATE', 'CHANGE_PERMISSIONS', 'CHANGE_SETTINGS'] or an empty array |
Source code in synapseclient/models/mixins/access_control.py
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 | |
get_permissions_async
async
¶
get_permissions_async(*, synapse_client: Optional[Synapse] = None) -> Permissions
Get the permissions that the caller has on an Entity.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
Permissions
|
A Permissions object |
Using this function:
Getting permissions for a Synapse Entity
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
syn = Synapse()
syn.login()
async def main():
permissions = await File(id="syn123").get_permissions_async()
asyncio.run(main())
Getting access types list from the Permissions object
permissions.access_types
Source code in synapseclient/models/mixins/access_control.py
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 | |
set_permissions_async
async
¶
set_permissions_async(principal_id: int = None, access_type: List[str] = None, modify_benefactor: bool = False, warn_if_inherits: bool = True, overwrite: bool = True, *, synapse_client: Optional[Synapse] = None) -> Dict[str, Union[str, list]]
Sets permission that a user or group has on an Entity. An Entity may have its own ACL or inherit its ACL from a benefactor.
| PARAMETER | DESCRIPTION |
|---|---|
principal_id
|
Identifier of a user or group.
TYPE:
|
access_type
|
Type of permission to be granted. One or more of CREATE, READ, DOWNLOAD, UPDATE, DELETE, CHANGE_PERMISSIONS. Defaults to ['READ', 'DOWNLOAD'] |
modify_benefactor
|
Set as True when modifying a benefactor's ACL. The term 'benefactor' is used to indicate which Entity an Entity inherits its ACL from. For example, a newly created Project will be its own benefactor, while a new FileEntity's benefactor will start off as its containing Project. If the entity already has local sharing settings the benefactor would be itself. It may also be the immediate parent, somewhere in the parent tree, or the project itself.
TYPE:
|
warn_if_inherits
|
When
TYPE:
|
overwrite
|
By default this function overwrites existing permissions for the specified user. Set this flag to False to add new permissions non-destructively.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Union[str, list]]
|
An Access Control List object matching https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/AccessControlList.html. |
Setting permissions
Grant all registered users download access
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
syn = Synapse()
syn.login()
async def main():
await File(id="syn123").set_permissions_async(principal_id=273948, access_type=['READ','DOWNLOAD'])
asyncio.run(main())
Grant the public view access
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
syn = Synapse()
syn.login()
async def main():
await File(id="syn123").set_permissions_async(principal_id=273949, access_type=['READ'])
asyncio.run(main())
Source code in synapseclient/models/mixins/access_control.py
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 | |
delete_permissions_async
async
¶
delete_permissions_async(include_self: bool = True, include_container_content: bool = False, recursive: bool = False, target_entity_types: Optional[List[str]] = None, dry_run: bool = False, show_acl_details: bool = True, show_files_in_containers: bool = True, *, synapse_client: Optional[Synapse] = None, _benefactor_tracker: Optional[BenefactorTracker] = None) -> None
Delete the entire Access Control List (ACL) for a given Entity. This is not scoped to a specific user or group, but rather removes all permissions associated with the Entity. After this operation, the Entity will inherit permissions from its benefactor, which is typically its parent entity or the Project it belongs to.
In order to remove permissions for a specific user or group, you
should use the set_permissions_async method with the access_type set to
an empty list.
By default, Entities such as FileEntity and Folder inherit their permission from their containing Project. For such Entities the Project is the Entity's 'benefactor'. This permission inheritance can be overridden by creating an ACL for the Entity. When this occurs the Entity becomes its own benefactor and all permission are determined by its own ACL.
If the ACL of an Entity is deleted, then its benefactor will automatically be set to its parent's benefactor.
Special notice for Projects: The ACL for a Project cannot be deleted, you must individually update or revoke the permissions for each user or group.
| PARAMETER | DESCRIPTION |
|---|---|
include_self
|
If True (default), delete the ACL of the current entity. If False, skip deleting the ACL of the current entity.
TYPE:
|
include_container_content
|
If True, delete ACLs from contents directly within containers (files and folders inside self). This must be set to True for recursive to have any effect. Defaults to False.
TYPE:
|
recursive
|
If True and the entity is a container (e.g., Project or Folder),
recursively process child containers. Note that this must be used with
include_container_content=True to have any effect. Setting recursive=True
with include_container_content=False will raise a ValueError.
Only works on classes that support the
TYPE:
|
target_entity_types
|
Specify which entity types to process when deleting ACLs.
Allowed values are "folder", "file", "project", "table", "entityview",
"materializedview", "virtualtable", "dataset", "datasetcollection",
"submissionview" (case-insensitive). If None, defaults to ["folder", "file"].
This does not affect the entity type of the current entity, which is always
processed if |
dry_run
|
If True, log the changes that would be made instead of actually performing the deletions. When enabled, all ACL deletion operations are simulated and logged at info level. Defaults to False.
TYPE:
|
show_acl_details
|
When dry_run=True, controls whether current ACL details are displayed for entities that will have their permissions changed. If True (default), shows detailed ACL information. If False, hides ACL details for cleaner output. Has no effect when dry_run=False.
TYPE:
|
show_files_in_containers
|
When dry_run=True, controls whether files within containers are displayed in the preview. If True (default), shows all files. If False, hides files when their only change is benefactor inheritance (but still shows files with local ACLs being deleted). Has no effect when dry_run=False.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
_benefactor_tracker
|
Internal use tracker for managing benefactor relationships. Used for recursive functionality to track which entities will be affected
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the entity does not have an ID or if an invalid entity type is provided. |
SynapseHTTPError
|
If there are permission issues or if the entity already inherits permissions. |
Exception
|
For any other errors that may occur during the process. |
Note: The caller must be granted ACCESS_TYPE.CHANGE_PERMISSIONS on the Entity to call this method.
Delete permissions for a single entity
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
syn = Synapse()
syn.login()
async def main():
await File(id="syn123").delete_permissions_async()
asyncio.run(main())
Delete permissions recursively for a folder and all its children
import asyncio
from synapseclient import Synapse
from synapseclient.models import Folder
syn = Synapse()
syn.login()
async def main():
# Delete permissions for this folder only (does not affect children)
await Folder(id="syn123").delete_permissions_async()
# Delete permissions for all files and folders directly within this folder,
# but not the folder itself
await Folder(id="syn123").delete_permissions_async(
include_self=False,
include_container_content=True
)
# Delete permissions for all items in the entire hierarchy (folders and their files)
# Both recursive and include_container_content must be True
await Folder(id="syn123").delete_permissions_async(
recursive=True,
include_container_content=True
)
# Delete permissions only for folder entities within this folder recursively
# and their contents
await Folder(id="syn123").delete_permissions_async(
recursive=True,
include_container_content=True,
target_entity_types=["folder"]
)
# Delete permissions only for files within this folder and all subfolders
await Folder(id="syn123").delete_permissions_async(
include_self=False,
recursive=True,
include_container_content=True,
target_entity_types=["file"]
)
# Delete permissions for specific entity types (e.g., tables and views)
await Folder(id="syn123").delete_permissions_async(
recursive=True,
include_container_content=True,
target_entity_types=["table", "entityview", "materializedview"]
)
# Dry run example: Log what would be deleted without making changes
await Folder(id="syn123").delete_permissions_async(
recursive=True,
include_container_content=True,
dry_run=True
)
asyncio.run(main())
Source code in synapseclient/models/mixins/access_control.py
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 | |
list_acl_async
async
¶
list_acl_async(recursive: bool = False, include_container_content: bool = False, target_entity_types: Optional[List[str]] = None, log_tree: bool = False, *, synapse_client: Optional[Synapse] = None, _progress_bar: Optional[tqdm] = None) -> AclListResult
List the Access Control Lists (ACLs) for this entity and optionally its children.
This function returns the local sharing settings for the entity and optionally its children. It provides a mapping of all ACLs for the given container/entity.
Important Note: This function returns the LOCAL sharing settings only, not the effective permissions that each Synapse User ID/Team has on the entities. More permissive permissions could be granted via a Team that the user has access to that has permissions on the entity, or through inheritance from parent entities.
| PARAMETER | DESCRIPTION |
|---|---|
recursive
|
If True and the entity is a container (e.g., Project or Folder),
recursively process child containers. Note that this must be used with
include_container_content=True to have any effect. Setting recursive=True
with include_container_content=False will raise a ValueError.
Only works on classes that support the
TYPE:
|
include_container_content
|
If True, include ACLs from contents directly within containers (files and folders inside self). This must be set to True for recursive to have any effect. Defaults to False.
TYPE:
|
target_entity_types
|
Specify which entity types to process when listing ACLs. Allowed values are "folder", "file", "project", "table", "entityview", "materializedview", "virtualtable", "dataset", "datasetcollection", "submissionview" (case-insensitive). If None, defaults to ["folder", "file"]. |
log_tree
|
If True, logs the ACL results to console in ASCII tree format showing entity hierarchies and their ACL permissions in a tree-like structure. Defaults to False.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
_progress_bar
|
Internal parameter. Progress bar instance to use for updates when called recursively. Should not be used by external callers.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AclListResult
|
An AclListResult object containing a structured representation of ACLs where: |
AclListResult
|
|
AclListResult
|
|
AclListResult
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the entity does not have an ID or if an invalid entity type is provided. |
SynapseHTTPError
|
If there are permission issues accessing ACLs. |
Exception
|
For any other errors that may occur during the process. |
List ACLs for a single entity
import asyncio
from synapseclient import Synapse
from synapseclient.models import File
syn = Synapse()
syn.login()
async def main():
acl_result = await File(id="syn123").list_acl_async()
print(acl_result)
# Access entity ACLs (entity_acls is a list, not a dict)
for entity_acl in acl_result.all_entity_acls:
if entity_acl.entity_id == "syn123":
# Access individual ACL entries
for acl_entry in entity_acl.acl_entries:
if acl_entry.principal_id == "273948":
print(f"Principal 273948 has permissions: {acl_entry.permissions}")
# I can also access the ACL for the file itself
print(acl_result.entity_acl)
print(acl_result)
asyncio.run(main())
List ACLs recursively for a folder and all its children
import asyncio
from synapseclient import Synapse
from synapseclient.models import Folder
syn = Synapse()
syn.login()
async def main():
acl_result = await Folder(id="syn123").list_acl_async(
recursive=True,
include_container_content=True
)
# Access each entity's ACL (entity_acls is a list)
for entity_acl in acl_result.all_entity_acls:
print(f"Entity {entity_acl.entity_id} has ACL with {len(entity_acl.acl_entries)} principals")
# I can also access the ACL for the folder itself
print(acl_result.entity_acl)
# List ACLs for only folder entities
folder_acl_result = await Folder(id="syn123").list_acl_async(
recursive=True,
include_container_content=True,
target_entity_types=["folder"]
)
# List ACLs for specific entity types (e.g., tables and views)
table_view_acl_result = await Folder(id="syn123").list_acl_async(
recursive=True,
include_container_content=True,
target_entity_types=["table", "entityview", "materializedview"]
)
asyncio.run(main())
List ACLs with ASCII tree visualization
When log_tree=True, the ACLs will be logged in a tree format. Additionally,
the ascii_tree attribute of the AclListResult will contain the ASCII tree
representation of the ACLs.
import asyncio
from synapseclient import Synapse
from synapseclient.models import Folder
syn = Synapse()
syn.login()
async def main():
acl_result = await Folder(id="syn123").list_acl_async(
recursive=True,
include_container_content=True,
log_tree=True, # Enable ASCII tree logging
)
# The ASCII tree representation of the ACLs will also be available
# in acl_result.ascii_tree
print(acl_result.ascii_tree)
asyncio.run(main())
Source code in synapseclient/models/mixins/access_control.py
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 | |
bind_schema_async
async
¶
bind_schema_async(json_schema_uri: str, *, enable_derived_annotations: bool = False, synapse_client: Optional[Synapse] = None) -> JSONSchemaBinding
Bind a JSON schema to the entity.
| PARAMETER | DESCRIPTION |
|---|---|
json_schema_uri
|
The URI of the JSON schema to bind to the entity.
TYPE:
|
enable_derived_annotations
|
If true, enable derived annotations. Defaults to False.
TYPE:
|
synapse_client
|
The Synapse client instance. If not provided, the last created instance from the Synapse class constructor will be used. |
| RETURNS | DESCRIPTION |
|---|---|
JSONSchemaBinding
|
An object containing details about the JSON schema binding. |
Using this function
Binding JSON schema to a folder or a file. This example expects that you
have a Synapse project to use, and a file to upload. Set the PROJECT_NAME
and FILE_PATH variables to your project name and file path respectively.
import asyncio
from synapseclient import Synapse
from synapseclient.models import File, Folder
syn = Synapse()
syn.login()
# Define Project and JSON schema info
PROJECT_NAME = "test_json_schema_project" # replace with your project name
FILE_PATH = "~/Sample.txt" # replace with your test file path
PROJECT_ID = syn.findEntityId(name=PROJECT_NAME)
ORG_NAME = "UniqueOrg" # replace with your organization name
SCHEMA_NAME = "myTestSchema" # replace with your schema name
FOLDER_NAME = "test_script_folder"
VERSION = "0.0.1"
SCHEMA_URI = f"{ORG_NAME}-{SCHEMA_NAME}-{VERSION}"
# Create organization (if not already created)
js = syn.service("json_schema")
all_orgs = js.list_organizations()
for org in all_orgs:
if org["name"] == ORG_NAME:
print(f"Organization {ORG_NAME} already exists: {org}")
break
else:
print(f"Creating organization {ORG_NAME}.")
created_organization = js.create_organization(ORG_NAME)
print(f"Created organization: {created_organization}")
my_test_org = js.JsonSchemaOrganization(ORG_NAME)
test_schema = my_test_org.get_json_schema(SCHEMA_NAME)
if not test_schema:
# Create the schema (if not already created)
schema_definition = {
"$id": "mySchema",
"type": "object",
"properties": {
"foo": {"type": "string"},
"bar": {"type": "integer"},
},
"required": ["foo"]
}
test_schema = my_test_org.create_json_schema(schema_definition, SCHEMA_NAME, VERSION)
print(f"Created new schema: {SCHEMA_NAME}")
async def main():
# Create a test folder
test_folder = Folder(name=FOLDER_NAME, parent_id=PROJECT_ID)
await test_folder.store_async()
print(f"Created test folder: {FOLDER_NAME}")
# Bind JSON schema to the folder
bound_schema = await test_folder.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Result from binding schema to folder: {bound_schema}")
# Create and bind schema to a file
example_file = File(
path=FILE_PATH, # Replace with your test file path
parent_id=test_folder.id,
)
await example_file.store_async()
bound_schema_file = await example_file.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Result from binding schema to file: {bound_schema_file}")
asyncio.run(main())
Source code in synapseclient/models/mixins/json_schema.py
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 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 | |
get_schema_async
async
¶
get_schema_async(*, synapse_client: Optional[Synapse] = None) -> JSONSchemaBinding
Get the JSON schema bound to the entity.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
The Synapse client instance. If not provided, the last created instance from the Synapse class constructor will be used. |
| RETURNS | DESCRIPTION |
|---|---|
JSONSchemaBinding
|
An object containing details about the bound JSON schema. |
Using this function
Retrieving the bound JSON schema from a folder or file. This example demonstrates
how to get existing schema bindings from entities that already have schemas bound.
Set the PROJECT_NAME and FILE_PATH variables to your project name
and file path respectively.
import asyncio
from synapseclient import Synapse
from synapseclient.models import File, Folder
syn = Synapse()
syn.login()
# Define Project and JSON schema info
PROJECT_NAME = "test_json_schema_project" # replace with your project name
FILE_PATH = "~/Sample.txt" # replace with your test file path
PROJECT_ID = syn.findEntityId(name=PROJECT_NAME)
ORG_NAME = "UniqueOrg" # replace with your organization name
SCHEMA_NAME = "myTestSchema" # replace with your schema name
FOLDER_NAME = "test_script_folder"
VERSION = "0.0.1"
SCHEMA_URI = f"{ORG_NAME}-{SCHEMA_NAME}-{VERSION}"
# Create organization (if not already created)
js = syn.service("json_schema")
all_orgs = js.list_organizations()
for org in all_orgs:
if org["name"] == ORG_NAME:
print(f"Organization {ORG_NAME} already exists: {org}")
break
else:
print(f"Creating organization {ORG_NAME}.")
created_organization = js.create_organization(ORG_NAME)
print(f"Created organization: {created_organization}")
my_test_org = js.JsonSchemaOrganization(ORG_NAME)
test_schema = my_test_org.get_json_schema(SCHEMA_NAME)
if not test_schema:
# Create the schema (if not already created)
schema_definition = {
"$id": "mySchema",
"type": "object",
"properties": {
"foo": {"type": "string"},
"bar": {"type": "integer"},
},
"required": ["foo"]
}
test_schema = my_test_org.create_json_schema(schema_definition, SCHEMA_NAME, VERSION)
print(f"Created new schema: {SCHEMA_NAME}")
async def main():
# Create a test folder
test_folder = Folder(name=FOLDER_NAME, parent_id=PROJECT_ID)
await test_folder.store_async()
print(f"Created test folder: {FOLDER_NAME}")
# Bind JSON schema to the folder first
bound_schema = await test_folder.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to folder: {bound_schema}")
# Create and bind schema to a file
example_file = File(
path=FILE_PATH, # Replace with your test file path
parent_id=test_folder.id,
)
await example_file.store_async()
bound_schema_file = await example_file.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to file: {bound_schema_file}")
# Retrieve the bound schema from the folder
bound_schema = await test_folder.get_schema_async()
print(f"Retrieved schema from folder: {bound_schema}")
# Retrieve the bound schema from the file
bound_schema_file = await example_file.get_schema_async()
print(f"Retrieved schema from file: {bound_schema_file}")
asyncio.run(main())
Source code in synapseclient/models/mixins/json_schema.py
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 | |
unbind_schema_async
async
¶
Unbind the JSON schema bound to the entity.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
The Synapse client instance. If not provided, the last created instance from the Synapse class constructor will be used. |
Using this function
Unbinding a JSON schema from a folder or file. This example demonstrates
how to remove schema bindings from entities. Assumes entities already have
schemas bound. Set the PROJECT_NAME and FILE_PATH variables to your
project name and file path respectively.
import asyncio
from synapseclient import Synapse
from synapseclient.models import File, Folder
syn = Synapse()
syn.login()
# Define Project and JSON schema info
PROJECT_NAME = "test_json_schema_project" # replace with your project name
FILE_PATH = "~/Sample.txt" # replace with your test file path
PROJECT_ID = syn.findEntityId(name=PROJECT_NAME)
ORG_NAME = "UniqueOrg" # replace with your organization name
SCHEMA_NAME = "myTestSchema" # replace with your schema name
FOLDER_NAME = "test_script_folder"
VERSION = "0.0.1"
SCHEMA_URI = f"{ORG_NAME}-{SCHEMA_NAME}-{VERSION}"
# Create organization (if not already created)
js = syn.service("json_schema")
all_orgs = js.list_organizations()
for org in all_orgs:
if org["name"] == ORG_NAME:
print(f"Organization {ORG_NAME} already exists: {org}")
break
else:
print(f"Creating organization {ORG_NAME}.")
created_organization = js.create_organization(ORG_NAME)
print(f"Created organization: {created_organization}")
my_test_org = js.JsonSchemaOrganization(ORG_NAME)
test_schema = my_test_org.get_json_schema(SCHEMA_NAME)
if not test_schema:
# Create the schema (if not already created)
schema_definition = {
"$id": "mySchema",
"type": "object",
"properties": {
"foo": {"type": "string"},
"bar": {"type": "integer"},
},
"required": ["foo"]
}
test_schema = my_test_org.create_json_schema(schema_definition, SCHEMA_NAME, VERSION)
print(f"Created new schema: {SCHEMA_NAME}")
async def main():
# Create a test folder
test_folder = Folder(name=FOLDER_NAME, parent_id=PROJECT_ID)
await test_folder.store_async()
print(f"Created test folder: {FOLDER_NAME}")
# Bind JSON schema to the folder first
bound_schema = await test_folder.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to folder: {bound_schema}")
# Create and bind schema to a file
example_file = File(
path=FILE_PATH, # Replace with your test file path
parent_id=test_folder.id,
)
await example_file.store_async()
print(f"Created test file: {FILE_PATH}")
bound_schema_file = await example_file.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to file: {bound_schema_file}")
# Unbind the schema from the folder
await test_folder.unbind_schema_async()
print("Successfully unbound schema from folder")
# Unbind the schema from the file
await example_file.unbind_schema_async()
print("Successfully unbound schema from file")
asyncio.run(main())
Source code in synapseclient/models/mixins/json_schema.py
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 | |
validate_schema_async
async
¶
validate_schema_async(*, synapse_client: Optional[Synapse] = None) -> Union[JSONSchemaValidation, InvalidJSONSchemaValidation]
Validate the entity against the bound JSON schema.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
The Synapse client instance. If not provided, the last created instance from the Synapse class constructor will be used. |
| RETURNS | DESCRIPTION |
|---|---|
Union[JSONSchemaValidation, InvalidJSONSchemaValidation]
|
The validation results. |
Using this function
Validating a folder or file against the bound JSON schema. This example demonstrates
how to validate entities with annotations against their bound schemas. Requires entities
to have schemas already bound. Set the PROJECT_NAME and FILE_PATH variables to your project name
and file path respectively.
import asyncio
import time
from synapseclient import Synapse
from synapseclient.models import File, Folder
syn = Synapse()
syn.login()
# Define Project and JSON schema info
PROJECT_NAME = "test_json_schema_project" # replace with your project name
FILE_PATH = "~/Sample.txt" # replace with your test file path
PROJECT_ID = syn.findEntityId(name=PROJECT_NAME)
ORG_NAME = "UniqueOrg" # replace with your organization name
SCHEMA_NAME = "myTestSchema" # replace with your schema name
FOLDER_NAME = "test_script_folder"
VERSION = "0.0.1"
SCHEMA_URI = f"{ORG_NAME}-{SCHEMA_NAME}-{VERSION}"
# Create organization (if not already created)
js = syn.service("json_schema")
all_orgs = js.list_organizations()
for org in all_orgs:
if org["name"] == ORG_NAME:
print(f"Organization {ORG_NAME} already exists: {org}")
break
else:
print(f"Creating organization {ORG_NAME}.")
created_organization = js.create_organization(ORG_NAME)
print(f"Created organization: {created_organization}")
my_test_org = js.JsonSchemaOrganization(ORG_NAME)
test_schema = my_test_org.get_json_schema(SCHEMA_NAME)
if not test_schema:
# Create the schema (if not already created)
schema_definition = {
"$id": "mySchema",
"type": "object",
"properties": {
"foo": {"type": "string"},
"bar": {"type": "integer"},
},
"required": ["foo"]
}
test_schema = my_test_org.create_json_schema(schema_definition, SCHEMA_NAME, VERSION)
print(f"Created new schema: {SCHEMA_NAME}")
async def main():
# Create a test folder
test_folder = Folder(name=FOLDER_NAME, parent_id=PROJECT_ID)
await test_folder.store_async()
print(f"Created test folder: {FOLDER_NAME}")
# Bind JSON schema to the folder
bound_schema = await test_folder.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to folder: {bound_schema}")
# Create and bind schema to a file
example_file = File(
path=FILE_PATH, # Replace with your test file path
parent_id=test_folder.id,
)
await example_file.store_async()
bound_schema_file = await example_file.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to file: {bound_schema_file}")
# Validate the folder entity against the bound schema
test_folder.annotations = {"foo": "test_value", "bar": 42} # Example annotations
await test_folder.store_async()
print("Added annotations to folder and stored")
time.sleep(2) # Allow time for processing
validation_response = await test_folder.validate_schema_async()
print(f"Folder validation response: {validation_response}")
# Validate the file entity against the bound schema
example_file.annotations = {"foo": "test_value", "bar": 43} # Example annotations
await example_file.store_async()
print("Added annotations to file and stored")
time.sleep(2) # Allow time for processing
validation_response_file = await example_file.validate_schema_async()
print(f"File validation response: {validation_response_file}")
asyncio.run(main())
Source code in synapseclient/models/mixins/json_schema.py
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 | |
get_schema_derived_keys_async
async
¶
get_schema_derived_keys_async(*, synapse_client: Optional[Synapse] = None) -> JSONSchemaDerivedKeys
Retrieve derived JSON schema keys for the entity.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
The Synapse client instance. If not provided, the last created instance from the Synapse class constructor will be used. |
| RETURNS | DESCRIPTION |
|---|---|
JSONSchemaDerivedKeys
|
An object containing the derived keys for the entity. |
Using this function
Retrieving derived keys from a folder or file. This example demonstrates
how to get derived annotation keys from schemas with constant values.
Set the PROJECT_NAME variable to your project name.
import asyncio
from synapseclient import Synapse
from synapseclient.models import File, Folder
syn = Synapse()
syn.login()
# Define Project and JSON schema info
PROJECT_NAME = "test_json_schema_project" # replace with your project name
FILE_PATH = "~/Sample.txt" # replace with your test file path
PROJECT_ID = syn.findEntityId(name=PROJECT_NAME)
ORG_NAME = "UniqueOrg" # replace with your organization name
DERIVED_TEST_SCHEMA_NAME = "myTestDerivedSchema" # replace with your derived schema name
FOLDER_NAME = "test_script_folder"
VERSION = "0.0.1"
SCHEMA_URI = f"{ORG_NAME}-{DERIVED_TEST_SCHEMA_NAME}-{VERSION}"
# Create organization (if not already created)
js = syn.service("json_schema")
all_orgs = js.list_organizations()
for org in all_orgs:
if org["name"] == ORG_NAME:
print(f"Organization {ORG_NAME} already exists: {org}")
break
else:
print(f"Creating organization {ORG_NAME}.")
created_organization = js.create_organization(ORG_NAME)
print(f"Created organization: {created_organization}")
my_test_org = js.JsonSchemaOrganization(ORG_NAME)
test_schema = my_test_org.get_json_schema(DERIVED_TEST_SCHEMA_NAME)
if not test_schema:
# Create the schema (if not already created)
schema_definition = {
"$id": "mySchema",
"type": "object",
"properties": {
"foo": {"type": "string"},
"baz": {"type": "string", "const": "example_value"}, # Example constant for derived annotation
"bar": {"type": "integer"},
},
"required": ["foo"]
}
test_schema = my_test_org.create_json_schema(schema_definition, DERIVED_TEST_SCHEMA_NAME, VERSION)
print(f"Created new derived schema: {DERIVED_TEST_SCHEMA_NAME}")
async def main():
# Create a test folder
test_folder = Folder(name=FOLDER_NAME, parent_id=PROJECT_ID)
await test_folder.store_async()
print(f"Created test folder: {FOLDER_NAME}")
# Bind JSON schema to the folder
bound_schema = await test_folder.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to folder with derived annotations: {bound_schema}")
# Create and bind schema to a file
example_file = File(
path=FILE_PATH, # Replace with your test file path
parent_id=test_folder.id,
)
await example_file.store_async()
bound_schema_file = await example_file.bind_schema_async(
json_schema_uri=SCHEMA_URI,
enable_derived_annotations=True
)
print(f"Bound schema to file with derived annotations: {bound_schema_file}")
# Get the derived keys from the bound schema of the folder
test_folder.annotations = {"foo": "test_value_new", "bar": 42} # Example annotations
await test_folder.store_async()
print("Added annotations to folder and stored")
derived_keys = await test_folder.get_schema_derived_keys_async()
print(f"Derived keys from folder: {derived_keys}")
# Get the derived keys from the bound schema of the file
example_file.annotations = {"foo": "test_value_new", "bar": 43} # Example annotations
await example_file.store_async()
print("Added annotations to file and stored")
derived_keys_file = await example_file.get_schema_derived_keys_async()
print(f"Derived keys from file: {derived_keys_file}")
asyncio.run(main())
Source code in synapseclient/models/mixins/json_schema.py
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 | |
synapseclient.models.RecordBasedMetadataTaskProperties
dataclass
¶
A CurationTaskProperties for record-based metadata.
Represents a Synapse RecordBasedMetadataTaskProperties.
| ATTRIBUTE | DESCRIPTION |
|---|---|
record_set_id |
The synId of the RecordSet that will contain all record-based metadata |
Source code in synapseclient/models/curation.py
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 | |
synapseclient.models.FileBasedMetadataTaskProperties
dataclass
¶
A CurationTaskProperties for file-based data, describing where data is uploaded and a view which contains the annotations.
Represents a Synapse FileBasedMetadataTaskProperties.
| ATTRIBUTE | DESCRIPTION |
|---|---|
upload_folder_id |
The synId of the folder where data files of this type are to be uploaded |
file_view_id |
The synId of the FileView that shows all data of this type |
Source code in synapseclient/models/curation.py
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 | |
synapseclient.models.Grid
dataclass
¶
Bases: GridSynchronousProtocol
A GridSession provides functionality to create and manage grid sessions in Synapse. Grid sessions are used for curation workflows where data can be edited in a grid format and then exported back to record sets.
| ATTRIBUTE | DESCRIPTION |
|---|---|
record_set_id |
The synId of the RecordSet to use for initializing the grid |
initial_query |
Initialize a grid session from an EntityView. Mutually exclusive with record_set_id. |
owner_principal_id |
The principal ID (user or team) that will own the created grid session. When not provided, the principal ID of the caller is used.
TYPE:
|
session_id |
The unique sessionId that identifies the grid session |
started_by |
The user that started this session |
started_on |
The date-time when the session was started |
etag |
Changes when the session changes |
modified_on |
The date-time when the session was last changed |
last_replica_id_client |
The last replica ID issued to a client |
last_replica_id_service |
The last replica ID issued to a service |
grid_json_schema_id |
The $id of the JSON schema used for model validation |
source_entity_id |
The synId of the table/view/csv that this grid was cloned from |
record_set_version_number |
The version number of the exported record set |
validation_summary_statistics |
Summary statistics for validation results
TYPE:
|
Create and manage a grid session workflow
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
# Create a new grid session from a record set
grid = Grid(record_set_id="syn1234567")
grid = grid.create()
print(f"Created grid session: {grid.session_id}")
# Later, export the modified data back to the record set
grid = grid.export_to_record_set()
print(f"Exported to version: {grid.record_set_version_number}")
# Clean up by deleting the session when done
grid.delete()
Working with grid sessions using queries
from synapseclient import Synapse
from synapseclient.models import Grid
from synapseclient.models.table_components import Query
syn = Synapse()
syn.login()
# Create a grid from an entity view query
query = Query(sql="SELECT * FROM syn1234567")
grid = Grid(initial_query=query)
grid = grid.create()
# Work with the grid session...
# Export when ready
grid = grid.export_to_record_set()
Source code in synapseclient/models/curation.py
2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 | |
Methods:¶
create_async
async
¶
create_async(attach_to_previous_session=False, *, timeout: int = 120, synapse_client: Optional[Synapse] = None) -> Grid
Creates a new grid session from a record_set_id or initial_query.
When using record_set_id, first checks for existing active sessions that match
the record set before creating a new one. When using initial_query, always
creates a new session due to the complexity of matching query parameters.
| PARAMETER | DESCRIPTION |
|---|---|
attach_to_previous_session
|
If True and using
DEFAULT:
|
timeout
|
The number of seconds to wait for the job to complete or progress before raising a SynapseTimeoutError. Defaults to 120.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
GridSession
|
The GridSession object with populated session_id.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Create a grid session asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
async def main():
# Create a grid session from a record set
grid = Grid(record_set_id="syn1234567")
grid = await grid.create_async()
print(f"Created grid session: {grid.session_id}")
asyncio.run(main())
Source code in synapseclient/models/curation.py
3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 | |
export_to_record_set_async
async
¶
Exports the grid session data back to a record set. This will create a new version of the original record set with the modified data from the grid session.
| PARAMETER | DESCRIPTION |
|---|---|
timeout
|
The number of seconds to wait for the job to complete or progress before raising a SynapseTimeoutError. Defaults to 120.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
GridSession
|
The GridSession object with export information populated.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If session_id is not provided. |
Export grid session data back to record set asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
async def main():
# Export modified grid data back to the record set
grid = Grid(session_id="abc-123-def")
grid = await grid.export_to_record_set_async()
print(f"Exported to record set: {grid.record_set_id}")
print(f"Version number: {grid.record_set_version_number}")
if grid.validation_summary_statistics:
print(f"Valid records: {grid.validation_summary_statistics.number_of_valid_children}")
asyncio.run(main())
Source code in synapseclient/models/curation.py
3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 | |
synchronize_async
async
¶
Synchronizes the grid session's schema and row data against its source entity.
This is intended for grid sessions created from a file view via initial_query.
Grid sessions backed by a RecordSet should use export_to_record_set instead.
| PARAMETER | DESCRIPTION |
|---|---|
timeout
|
The number of seconds to wait for the job to complete or progress before raising a SynapseTimeoutError. Defaults to 120.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
Grid
|
The Grid object.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If session_id is not provided. |
Synchronize a grid session created from a file view
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
from synapseclient.models.table_components import Query
syn = Synapse()
syn.login()
async def main():
# First create a grid session from a file view
query = Query(sql="SELECT * FROM syn1234567")
grid = Grid(initial_query=query)
grid = await grid.create_async()
# Synchronize the grid with the latest state of the file view
grid = await grid.synchronize_async()
asyncio.run(main())
Source code in synapseclient/models/curation.py
3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 | |
download_csv_async
async
¶
download_csv_async(*, destination: Optional[str] = None, write_header: bool = True, include_row_id_and_row_version: bool = False, include_etag: bool = False, csv_table_descriptor: Optional[CsvTableDescriptor] = None, file_name: Optional[str] = None, timeout: int = 120, synapse_client: Optional[Synapse] = None) -> str
Asynchronously download the current state of this grid session as a CSV file.
Submits a DownloadFromGridRequest async job, waits for it to complete, then downloads the resulting CSV to the local filesystem.
| PARAMETER | DESCRIPTION |
|---|---|
destination
|
Local directory path where the CSV will be saved. The directory must already exist. If not provided, defaults to the current working directory. |
write_header
|
Whether the first line should contain column names as a header. Defaults to True.
TYPE:
|
include_row_id_and_row_version
|
Whether the first two columns should contain row ID and version. Defaults to False.
TYPE:
|
include_etag
|
Whether a column should contain the row etag. Defaults to False.
TYPE:
|
csv_table_descriptor
|
The description of the CSV format (delimiter, quote character, etc.). If not provided, the default CSV format will be used.
TYPE:
|
file_name
|
The optional name for the downloaded file. If not
provided, defaults to |
timeout
|
The number of seconds to wait for the async job to complete or progress before raising a SynapseTimeoutError. Defaults to 120.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The local path to the downloaded CSV file. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If session_id is not provided. |
Download a grid session as a CSV asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
async def main():
grid = Grid(session_id="abc-123-def")
path = await grid.download_csv_async(destination="./downloads")
print(f"Downloaded CSV to: {path}")
asyncio.run(main())
Download a grid session as a CSV with a custom file name asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
async def main():
grid = Grid(session_id="abc-123-def")
path = await grid.download_csv_async(
destination="./downloads", file_name="my_export.csv"
)
print(f"Downloaded CSV to: {path}")
asyncio.run(main())
Source code in synapseclient/models/curation.py
3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 | |
import_csv_async
async
¶
import_csv_async(path: str, *, timeout: int = 120, csv_table_descriptor: Optional[CsvTableDescriptor] = None, synapse_client: Optional[Synapse] = None) -> Grid
Import a CSV file into this grid session. Previews the file to determine the column schema, then imports the data. Currently supports only grids created from a record set.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Local path to the CSV file to import.
TYPE:
|
csv_table_descriptor
|
The description of the CSV format (delimiter, quote character, etc.). If not provided, the default CSV format will be used.
TYPE:
|
timeout
|
The number of seconds to wait for each async job to complete or progress before raising a SynapseTimeoutError. Defaults to 120.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
Grid
|
The Grid object. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If session_id is not provided. |
Import a CSV file into a grid session asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
async def main():
grid = Grid(session_id="abc-123-def")
grid = await grid.import_csv_async(path="/local/path/to/data.csv")
print(f"Import complete for session: {grid.session_id}")
asyncio.run(main())
Source code in synapseclient/models/curation.py
3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 | |
delete_async
async
¶
Delete the grid session.
Note: Only the user that created a grid session may delete it.
| PARAMETER | DESCRIPTION |
|---|---|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If session_id is not provided. |
Delete a grid session asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
async def main():
# Delete the grid session
grid = Grid(session_id="abc-123-def")
await grid.delete_async()
print("Grid session deleted successfully")
asyncio.run(main())
Source code in synapseclient/models/curation.py
3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 | |
list_async
async
classmethod
¶
list_async(source_id: Optional[str] = None, *, synapse_client: Optional[Synapse] = None) -> AsyncGenerator[Grid, None]
Generator to get a list of active grid sessions for the user.
| PARAMETER | DESCRIPTION |
|---|---|
source_id
|
Optional. When provided, only sessions with this synId will be returned. |
synapse_client
|
If not passed in and caching was not disabled by
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncGenerator[Grid, None]
|
Grid objects representing active grid sessions. |
List all active grid sessions asynchronously
import asyncio
from synapseclient import Synapse
from synapseclient.models import Grid
syn = Synapse()
syn.login()
async def main():
# List all active grid sessions for the user
async for grid in Grid.list_async():
print(f"Session ID: {grid.session_id}")
print(f"Source Entity: {grid.source_entity_id}")
print(f"Started: {grid.started_on}")
print("---")
# List grid sessions for a specific source
async for grid in Grid.list_async(source_id="syn1234567"):
print(f"Session ID: {grid.session_id}")
print(f"Modified: {grid.modified_on}")
asyncio.run(main())
Source code in synapseclient/models/curation.py
3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 | |
synapseclient.models.Query
dataclass
¶
Represents a SQL query with optional parameters.
This result is modeled from: https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/table/Query.html
Source code in synapseclient/models/table_components.py
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 | |
Attributes¶
additional_filters
class-attribute
instance-attribute
¶
Appends additional filters to the SQL query. These are applied before facets. Filters within the list have an AND relationship. If a WHERE clause already exists on the SQL query or facets are selected, it will also be ANDed with the query generated by these additional filters.
selected_facets
class-attribute
instance-attribute
¶
The selected facet filters
include_entity_etag
class-attribute
instance-attribute
¶
Optional, default false. When true, a query results against views will include the Etag of each entity in the results. Note: The etag is necessary to update Entities in the view.
select_file_column
class-attribute
instance-attribute
¶
The id of the column used to select file entities (e.g. to fetch the action required for download). The column needs to be an ENTITYID type column and be part of the schema of the underlying table/view.
select_file_version_column
class-attribute
instance-attribute
¶
The id of the column used as the version for selecting file entities when required (e.g. to add a materialized view query to the download cart with version enabled). The column needs to be an INTEGER type column and be part of the schema of the underlying table/view.
offset
class-attribute
instance-attribute
¶
The optional offset into the results
limit
class-attribute
instance-attribute
¶
The optional limit to the results