Folder¶
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.Folder
dataclass
¶
Bases: FolderSynchronousProtocol
, AccessControllable
, StorableContainer
, ContainerEntityJSONSchema
Folder is a hierarchical container for organizing data in Synapse.
ATTRIBUTE | DESCRIPTION |
---|---|
id |
The unique immutable ID for this folder. A new ID will be generated for new Folders. Once issued, this ID is guaranteed to never change or be re-issued. |
name |
The name of this folder. Must be 256 characters or less. Names may only contain: letters, numbers, spaces, underscores, hyphens, periods, plus signs, apostrophes, and parentheses. |
parent_id |
The ID of the Project or Folder that is the parent of this Folder. |
description |
The description of this entity. Must be 1000 characters or less. |
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. |
files |
Files that exist within this folder. |
folders |
Folders that exist within this folder. |
tables |
Tables that exist within this folder. |
entityviews |
Entity views that exist within this folder.
TYPE:
|
submissionviews |
Submission views that exist within this folder.
TYPE:
|
datasets |
Datasets that exist within this folder. |
datasetcollections |
Dataset collections that exist within this folder.
TYPE:
|
materializedviews |
Materialized views that exist within this folder.
TYPE:
|
virtualtables |
Virtual tables that exist within this folder.
TYPE:
|
annotations |
Additional metadata associated with the folder. 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:
|
create_or_update |
(Store only) Indicates whether the method should automatically perform an update if the resource conflicts with an existing Synapse object. When True this means that any changes to the resource will be non-destructive. This boolean is ignored if you've already stored or retrieved the resource
from Synapse for this instance at least once. Any changes to the resource
will be destructive in this case. For example if you want to delete the
content for a field you will need to call
TYPE:
|
Source code in synapseclient/models/folder.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
Functions¶
get_async
async
¶
get_async(parent: Optional[Union[Folder, Project]] = None, *, synapse_client: Optional[Synapse] = None) -> Folder
Get the folder metadata from Synapse. You are able to find a folder by either the id or the name and parent_id.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent folder or project this folder exists under. |
synapse_client
|
If not passed in and caching was not disabled by
|
RETURNS | DESCRIPTION |
---|---|
Folder
|
The folder object. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the folder does not have an id or a
(name and ( |
Source code in synapseclient/models/folder.py
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 |
|
store_async
async
¶
store_async(parent: Optional[Union[Folder, Project]] = None, failure_strategy: FailureStrategy = LOG_EXCEPTION, *, synapse_client: Optional[Synapse] = None) -> Folder
Store folders and files to synapse. If you have any files or folders attached
to this folder they will be stored as well. You may attach files and folders
to this folder by setting the files
and folders
attributes.
By default the store operation will non-destructively update the folder if
you have not already retrieved the folder from Synapse. If you have already
retrieved the folder from Synapse then the store operation will be destructive
and will overwrite the folder with the current state of this object. See the
create_or_update
attribute for more information.
PARAMETER | DESCRIPTION |
---|---|
parent
|
The parent folder or project to store the folder in. |
failure_strategy
|
Determines how to handle failures when storing attached Files and Folders under this Folder and an exception occurs.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
RETURNS | DESCRIPTION |
---|---|
Folder
|
The folder object. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the folder does not have an id or a
(name and ( |
Source code in synapseclient/models/folder.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
delete_async
async
¶
Delete the folder from Synapse by its id.
PARAMETER | DESCRIPTION |
---|---|
synapse_client
|
If not passed in and caching was not disabled by
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the folder does not have an id set. |
Source code in synapseclient/models/folder.py
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 |
|
copy_async
async
¶
copy_async(parent_id: str, copy_annotations: bool = True, exclude_types: Optional[List[str]] = None, file_update_existing: bool = False, file_copy_activity: Union[str, None] = 'traceback', *, synapse_client: Optional[Synapse] = None) -> Folder
Copy the folder to another Synapse location. This will recursively copy all Tables, Links, Files, and Folders within the folder.
PARAMETER | DESCRIPTION |
---|---|
parent_id
|
Synapse ID of a folder/project that the copied entity is being copied to
TYPE:
|
copy_annotations
|
True to copy the annotations.
TYPE:
|
exclude_types
|
A list of entity types ['file', 'table', 'link'] which determines which entity types to not copy. Defaults to an empty list. |
file_update_existing
|
When the destination has a file that has the same name, users can choose to update that file.
TYPE:
|
file_copy_activity
|
Has three options to set the activity of the copied file:
|
synapse_client
|
If not passed in and caching was not disabled by
|
RETURNS | DESCRIPTION |
---|---|
Folder
|
The copied folder object. |
Using this function
Assuming you have a folder with the ID "syn123" and you want to copy it to a project with the ID "syn456":
new_folder_instance = await Folder(id="syn123").copy_async(parent_id="syn456")
Copy the folder but do not persist annotations:
new_folder_instance = await Folder(id="syn123").copy_async(parent_id="syn456", copy_annotations=False)
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the folder does not have an ID and parent_id to copy. |
Source code in synapseclient/models/folder.py
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 |
|
sync_from_synapse_async
async
¶
sync_from_synapse_async(path: Optional[str] = None, recursive: bool = True, download_file: bool = True, if_collision: str = COLLISION_OVERWRITE_LOCAL, failure_strategy: FailureStrategy = LOG_EXCEPTION, include_activity: bool = True, follow_link: bool = False, link_hops: int = 1, queue: Queue = None, include_types: Optional[List[str]] = None, *, synapse_client: Optional[Synapse] = None) -> Self
Sync this container and all possible sub-folders from Synapse. By default this
will download the files that are found and it will populate the
files
and folders
attributes with the found files and folders, along with
all other entity types (tables, entityviews, etc.) present in the container.
If you only want to retrieve the full tree of metadata about your
container specify download_file
as False.
This works similar to synapseutils.syncFromSynapse, however, this does not currently support the writing of data to a manifest TSV file. This will be a future enhancement.
Supports syncing Files, Folders, Tables, EntityViews, SubmissionViews, Datasets,
DatasetCollections, MaterializedViews, and VirtualTables from Synapse. The
metadata for these entity types will be populated in their respective
attributes (files
, folders
, tables
, entityviews
, submissionviews
,
datasets
, datasetcollections
, materializedviews
, virtualtables
) if
they are found within the container.
PARAMETER | DESCRIPTION |
---|---|
path
|
An optional path where the file hierarchy will be reproduced. If not specified the files will by default be placed in the synapseCache. |
recursive
|
Whether or not to recursively get the entire hierarchy of the folder and sub-folders.
TYPE:
|
download_file
|
Whether to download the files found or not.
TYPE:
|
if_collision
|
Determines how to handle file collisions. May be
TYPE:
|
failure_strategy
|
Determines how to handle failures when retrieving children under this Folder and an exception occurs.
TYPE:
|
include_activity
|
Whether to include the activity of the files.
TYPE:
|
follow_link
|
Whether to follow a link entity or not. Links can be used to point at other Synapse entities.
TYPE:
|
link_hops
|
The number of hops to follow the link. A number of 1 is used to prevent circular references. There is nothing in place to prevent infinite loops. Be careful if setting this above 1.
TYPE:
|
queue
|
An optional queue to use to download files in parallel.
TYPE:
|
include_types
|
Must be a list of entity types (ie. ["folder","file"]) which
can be found
here.
Defaults to
|
synapse_client
|
If not passed in and caching was not disabled by
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The object that was called on. This will be the same object that was called on to start the sync. |
Using this function
Suppose I want to walk the immediate children of a folder without downloading the files:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Folder
async def my_function():
syn = Synapse()
syn.login()
my_folder = Folder(id="syn12345")
await my_folder.sync_from_synapse_async(download_file=False, recursive=False)
for folder in my_folder.folders:
print(folder.name)
for file in my_folder.files:
print(file.name)
for table in my_folder.tables:
print(table.name)
for dataset in my_folder.datasets:
print(dataset.name)
asyncio.run(my_function())
Suppose I want to download the immediate children of a folder:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Folder
async def my_function():
syn = Synapse()
syn.login()
my_folder = Folder(id="syn12345")
await my_folder.sync_from_synapse_async(path="/path/to/folder", recursive=False)
for folder in my_folder.folders:
print(folder.name)
for file in my_folder.files:
print(file.name)
asyncio.run(my_function())
Suppose I want to sync only specific entity types from a Project:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Project
async def my_function():
syn = Synapse()
syn.login()
my_project = Project(id="syn12345")
await my_project.sync_from_synapse_async(
path="/path/to/folder",
include_types=["folder", "file", "table", "dataset"]
)
# Access different entity types
for table in my_project.tables:
print(f"Table: {table.name}")
for dataset in my_project.datasets:
print(f"Dataset: {dataset.name}")
asyncio.run(my_function())
Suppose I want to download all the children of a Project and all sub-folders and files:
import asyncio
from synapseclient import Synapse
from synapseclient.models import Project
async def my_function():
syn = Synapse()
syn.login()
my_project = Project(id="syn12345")
await my_project.sync_from_synapse_async(path="/path/to/folder")
asyncio.run(my_function())
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the folder does not have an id set. |
A sequence diagram for this method is as follows:
sequenceDiagram
autonumber
participant project_or_folder
activate project_or_folder
project_or_folder->>sync_from_synapse: Recursive search and download files
activate sync_from_synapse
opt Current instance not retrieved from Synapse
sync_from_synapse->>project_or_folder: Call `.get()` method
project_or_folder-->>sync_from_synapse: .
end
loop For each return of the generator
sync_from_synapse->>client: call `.getChildren()` method
client-->>sync_from_synapse: .
note over sync_from_synapse: Append to a running list
end
loop For each child
note over sync_from_synapse: Create all `pending_tasks` at current depth
alt Child is File
note over sync_from_synapse: Append `file.get()` method
else Child is Folder
note over sync_from_synapse: Append `folder.get()` method
alt Recursive is True
note over sync_from_synapse: Append `folder.sync_from_synapse()` method
end
else Child is Link and hops > 0
note over sync_from_synapse: Append task to follow link
end
end
loop For each task in pending_tasks
par `file.get()`
sync_from_synapse->>File: Retrieve File metadata and Optionally download
File->>client: `.get()`
client-->>File: .
File-->>sync_from_synapse: .
and `folder.get()`
sync_from_synapse->>Folder: Retrieve Folder metadataa
Folder->>client: `.get()`
client-->>Folder: .
Folder-->>sync_from_synapse: .
and `folder.sync_from_synapse_async()`
note over sync_from_synapse: This is a recursive call to `sync_from_synapse`
sync_from_synapse->>sync_from_synapse: Recursive call to `.sync_from_synapse_async()`
and `_follow_link`
sync_from_synapse ->>client: call `get_entity_id_bundle2` function
client-->sync_from_synapse: .
note over sync_from_synapse: Do nothing if not link
note over sync_from_synapse: call `_create_task_for_child` and execute
end
end
deactivate sync_from_synapse
deactivate project_or_folder
Source code in synapseclient/models/mixins/storable_container.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
flatten_file_list
¶
Recursively loop over all of the already retrieved files and folders and return a list of all files in the container.
RETURNS | DESCRIPTION |
---|---|
List[File]
|
A list of all files in the container. |
Source code in synapseclient/models/mixins/storable_container.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
|
map_directory_to_all_contained_files
¶
Recursively loop over all of the already retrieved files and folders. Then return back a dictionary where the key is the path to the directory at each level. The value is a list of all files in that directory AND all files in the child directories.
This is used during the creation of the manifest TSV file during the syncFromSynapse utility function.
Using this function
Returning back a dict with 2 keys:
Given:
root_folder
├── sub_folder
│ ├── file1.txt
│ └── file2.txt
Returns:
{
"root_folder": [file1, file2],
"root_folder/sub_folder": [file1, file2]
}
Returning back a dict with 3 keys:
Given:
root_folder
├── sub_folder_1
│ ├── file1.txt
├── sub_folder_2
│ └── file2.txt
Returns:
{
"root_folder": [file1, file2],
"root_folder/sub_folder_1": [file1]
"root_folder/sub_folder_2": [file2]
}
PARAMETER | DESCRIPTION |
---|---|
root_path
|
The root path where the top level files are stored.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, List[File]]
|
A dictionary where the key is the path to the directory at each level. The value is a list of all files in that directory AND all files in the child directories. |
Source code in synapseclient/models/mixins/storable_container.py
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 |
|
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 |
|
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 |
|
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
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 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 |
|
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
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
|
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
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 |
|
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
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 |
|
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
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 |
|
get_schema_validation_statistics_async
async
¶
get_schema_validation_statistics_async(*, synapse_client: Optional[Synapse] = None) -> JSONSchemaValidationStatistics
Get validation statistics for a container 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 |
---|---|
JSONSchemaValidationStatistics
|
The validation statistics. |
Using this function
Retrieving validation statistics for a folder. This example demonstrates
how to get validation statistics for a container entity after creating
entities with various validation states. Set the PROJECT_NAME
variable to your project name.
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"},
"baz": {"type": "string", "const": "example_value"},
"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 files within the folder with invalid annotations to generate statistics
invalid_file1 = File(
path=FILE_PATH, # assumes you have something here or adjust path
parent_id=test_folder.id
)
invalid_file1.annotations = {"foo": 123, "bar": "not_an_integer"} # both invalid
await invalid_file1.store_async()
print("Created file with invalid annotations")
time.sleep(2) # Allow time for processing
stats = await test_folder.get_schema_validation_statistics_async()
print(f"Validation statistics: {stats}")
asyncio.run(main())
Source code in synapseclient/models/mixins/json_schema.py
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 |
|
get_invalid_validation_async
async
¶
get_invalid_validation_async(*, synapse_client: Optional[Synapse] = None) -> AsyncGenerator[InvalidJSONSchemaValidation, None]
Get invalid JSON schema validation results for a container entity.
PARAMETER | DESCRIPTION |
---|---|
synapse_client
|
The Synapse client instance. If not provided, the last created instance from the Synapse class constructor will be used. |
YIELDS | DESCRIPTION |
---|---|
AsyncGenerator[InvalidJSONSchemaValidation, None]
|
An object containing the validation response, all validation messages, and the validation exception details. |
Using this function
Retrieving invalid validation results for a folder. This example demonstrates
how to get detailed invalid validation results for child entities within a container.
Set the PROJECT_NAME
variable to your project name.
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"},
"baz": {"type": "string", "const": "example_value"},
"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 files within the folder with invalid annotations to generate invalid results
invalid_file1 = File(
path=FILE_PATH, # assumes you have something here or adjust path
parent_id=test_folder.id
)
invalid_file1.annotations = {"foo": 123, "bar": "not_an_integer"} # both invalid
await invalid_file1.store_async()
print("Created file with invalid annotations")
time.sleep(2) # Allow time for processing
print("Getting invalid validation results...")
gen = test_folder.get_invalid_validation_async(synapse_client=syn)
async for child in gen:
print(f"Invalid validation item: {child}")
asyncio.run(main())
Source code in synapseclient/models/mixins/json_schema.py
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 |
|