Core¶
This section is for super users / developers only. These functions are subject to change as they are internal development functions. Use at your own risk.
Upload¶
synapseclient.core.upload.upload_functions
¶
This module handles the various ways that a user can upload a file to Synapse.
Classes¶
Functions¶
upload_file_handle(syn, parent_entity, path, synapseStore=True, md5=None, file_size=None, mimetype=None, max_threads=None)
¶
Uploads the file in the provided path (if necessary) to a storage location based on project settings. Returns a new FileHandle as a dict to represent the stored file.
PARAMETER | DESCRIPTION |
---|---|
parent_entity |
Entity object or id of the parent entity.
TYPE:
|
path |
The file path to the file being uploaded
TYPE:
|
synapseStore |
If False, will not upload the file, but instead create an ExternalFileHandle that references the file on the local machine. If True, will upload the file based on StorageLocation determined by the entity_parent_id
TYPE:
|
md5 |
The MD5 checksum for the file, if known. Otherwise if the file is a local file, it will be calculated automatically.
TYPE:
|
file_size |
The size the file, if known. Otherwise if the file is a local file, it will be calculated automatically.
TYPE:
|
file_size |
The MIME type the file, if known. Otherwise if the file is a local file, it will be calculated automatically.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
A dictionary of a new FileHandle as a dict that represents the uploaded file |
Source code in synapseclient/core/upload/upload_functions.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
upload_synapse_sts_boto_s3(syn, parent_id, upload_destination, local_path, mimetype=None, md5=None)
¶
When uploading to Synapse storage normally the back end will generate a random prefix for our uploaded object. Since in this case the client is responsible for the remote key, the client will instead generate a random prefix. this both ensures we don't have a collision with an existing S3 object and also mitigates potential performance issues, although key locality performance issues are likely resolved as of: https://aws.amazon.com/about-aws/whats-new/2018/07/amazon-s3-announces-increased-request-rate-performance/
PARAMETER | DESCRIPTION |
---|---|
syn |
The synapse client
TYPE:
|
parent_id |
The synapse ID of the parent.
TYPE:
|
upload_destination |
The upload destination
|
local_path |
The local path to the file to upload.
TYPE:
|
mimetype |
The mimetype is known. Defaults to None.
TYPE:
|
md5 |
MD5 checksum for the file, if known.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
description |
Source code in synapseclient/core/upload/upload_functions.py
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 |
|
Multipart Upload¶
synapseclient.core.upload.multipart_upload
¶
Implements the client side of Synapse's Multipart File Upload API, which provides a robust means of uploading large files (into the 10s of GiB). End users should not need to call any of the methods under UploadAttempt directly.
Classes¶
UploadAttempt
¶
Used to handle multi-threaded operations for uploading one or parts of a file.
Source code in synapseclient/core/upload/multipart_upload.py
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 |
|
Functions¶
multipart_upload_file(syn, file_path, dest_file_name=None, content_type=None, part_size=None, storage_location_id=None, preview=True, force_restart=False, max_threads=None, md5=None)
¶
Upload a file to a Synapse upload destination in chunks.
PARAMETER | DESCRIPTION |
---|---|
syn |
a Synapse object
|
file_path |
the file to upload
TYPE:
|
dest_file_name |
upload as a different filename
TYPE:
|
content_type |
Refers to the Content-Type of the API request.
TYPE:
|
part_size |
Number of bytes per part. Minimum is 5MiB (5 * 1024 * 1024 bytes).
TYPE:
|
storage_location_id |
an id indicating where the file should be stored. Retrieved from Synapse's UploadDestination
TYPE:
|
preview |
True to generate a preview
TYPE:
|
force_restart |
True to restart a previously initiated upload from scratch, False to try to resume
TYPE:
|
max_threads |
number of concurrent threads to devote to upload
TYPE:
|
md5 |
The MD5 of the file. If not provided, it will be calculated.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
a File Handle ID |
Keyword arguments are passed down to _multipart_upload().
Source code in synapseclient/core/upload/multipart_upload.py
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 |
|
multipart_upload_string(syn, text, dest_file_name=None, part_size=None, content_type=None, storage_location_id=None, preview=True, force_restart=False, max_threads=None)
¶
Upload a file to a Synapse upload destination in chunks.
PARAMETER | DESCRIPTION |
---|---|
syn |
a Synapse object
|
text |
a string to upload as a file.
TYPE:
|
dest_file_name |
upload as a different filename
TYPE:
|
content_type |
Refers to the Content-Type of the API request.
TYPE:
|
part_size |
number of bytes per part. Minimum 5MB.
TYPE:
|
storage_location_id |
an id indicating where the file should be stored. Retrieved from Synapse's UploadDestination
TYPE:
|
preview |
True to generate a preview
TYPE:
|
force_restart |
True to restart a previously initiated upload from scratch, False to try to resume
TYPE:
|
max_threads |
number of concurrent threads to devote to upload
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
a File Handle ID |
Keyword arguments are passed down to _multipart_upload().
Source code in synapseclient/core/upload/multipart_upload.py
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 |
|
multipart_copy(syn, source_file_handle_association, dest_file_name=None, part_size=None, storage_location_id=None, preview=True, force_restart=False, max_threads=None)
¶
Makes a Multipart Upload Copy Request. This request performs a copy of an existing file handle without data transfer from the client.
PARAMETER | DESCRIPTION |
---|---|
syn |
A Synapse object
|
source_file_handle_association |
Describes an association of a FileHandle with another object.
|
dest_file_name |
The name of the file to be uploaded.
TYPE:
|
part_size |
The size that each part will be (in bytes).
TYPE:
|
storage_location_id |
The identifier of the storage location where this file should be copied to. The user must be the owner of the storage location.
TYPE:
|
preview |
True to generate a preview of the data.
TYPE:
|
force_restart |
True to restart a previously initiated upload from scratch, False to try to resume.
TYPE:
|
max_threads |
Number of concurrent threads to devote to copy.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
a File Handle ID |
Keyword arguments are passed down to _multipart_upload().
Source code in synapseclient/core/upload/multipart_upload.py
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 |
|
_multipart_upload(syn, dest_file_name, upload_request, part_fn, md5_fn, force_restart=False, max_threads=None)
¶
Calls upon an UploadAttempt object to initiate and/or retry a multipart file upload or copy. This function is wrapped by multipart_upload_file, multipart_upload_string, and multipart_copy. Retries cannot exceed 7 retries per call.
PARAMETER | DESCRIPTION |
---|---|
syn |
A Synapse object
|
dest_file_name |
upload as a different filename
|
upload_request |
A dictionary object with the user-fed logistical details of the upload/copy request.
|
part_fn |
Function to calculate the partSize of each part
|
md5_fn |
Function to calculate the MD5 of the file-like object
|
max_threads |
number of concurrent threads to devote to upload.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
A File Handle ID |
Source code in synapseclient/core/upload/multipart_upload.py
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 |
|
Upload Async¶
synapseclient.core.upload.upload_functions_async
¶
This module handles the various ways that a user can upload a file to Synapse.
Classes¶
Functions¶
upload_file_handle(syn, parent_entity_id, path, synapse_store=True, md5=None, file_size=None, mimetype=None)
async
¶
Uploads the file in the provided path (if necessary) to a storage location based on project settings. Returns a new FileHandle as a dict to represent the stored file.
PARAMETER | DESCRIPTION |
---|---|
syn |
The synapse client
TYPE:
|
parent_entity_id |
The ID of the parent entity that the file will be attached to.
TYPE:
|
path |
The file path to the file being uploaded
TYPE:
|
synapse_store |
If False, will not upload the file, but instead create an ExternalFileHandle that references the file on the local machine. If True, will upload the file based on StorageLocation determined by the parent_entity_id.
TYPE:
|
md5 |
The MD5 checksum for the file, if known. Otherwise if the file is a local file, it will be calculated automatically.
TYPE:
|
file_size |
The size the file, if known. Otherwise if the file is a local file, it will be calculated automatically.
TYPE:
|
mimetype |
The MIME type the file, if known. Otherwise if the file is a local file, it will be calculated automatically.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Union[str, int]]
|
A dictionary of a new FileHandle as a dict that represents the uploaded file |
Source code in synapseclient/core/upload/upload_functions_async.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 |
|
create_external_file_handle(syn, path, mimetype=None, md5=None, file_size=None)
async
¶
Create a file handle in Synapse without uploading any files. This is used in cases where one wishes to store a reference to a file that is not in Synapse.
Source code in synapseclient/core/upload/upload_functions_async.py
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 |
|
upload_external_file_handle_sftp(syn, file_path, sftp_url, mimetype=None, md5=None, storage_str=None)
async
¶
Upload a file to an SFTP server and create a file handle in Synapse.
Source code in synapseclient/core/upload/upload_functions_async.py
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 |
|
upload_synapse_s3(syn, file_path, storage_location_id=None, mimetype=None, force_restart=False, md5=None, storage_str=None)
async
¶
Upload a file to Synapse storage and create a file handle in Synapse.
Argments
syn: The synapse client file_path: The path to the file to upload. storage_location_id: The storage location ID. mimetype: The mimetype of the file. force_restart: If True, will force the upload to restart. md5: The MD5 checksum for the file. storage_str: The storage string.
RETURNS | DESCRIPTION |
---|---|
Dict[str, Union[str, int]]
|
A dictionary of the file handle. |
Source code in synapseclient/core/upload/upload_functions_async.py
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 |
|
upload_synapse_sts_boto_s3(syn, parent_id, upload_destination, local_path, mimetype=None, md5=None, storage_str=None)
async
¶
When uploading to Synapse storage normally the back end will generate a random prefix for our uploaded object. Since in this case the client is responsible for the remote key, the client will instead generate a random prefix. this both ensures we don't have a collision with an existing S3 object and also mitigates potential performance issues, although key locality performance issues are likely resolved as of: https://aws.amazon.com/about-aws/whats-new/2018/07/amazon-s3-announces-increased-request-rate-performance/
PARAMETER | DESCRIPTION |
---|---|
syn |
The synapse client
TYPE:
|
parent_id |
The synapse ID of the parent.
TYPE:
|
upload_destination |
The upload destination
TYPE:
|
local_path |
The local path to the file to upload.
TYPE:
|
mimetype |
The mimetype is known. Defaults to None.
TYPE:
|
md5 |
MD5 checksum for the file, if known.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Union[str, int, bool]]
|
description |
Source code in synapseclient/core/upload/upload_functions_async.py
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 |
|
upload_client_auth_s3(syn, file_path, bucket, endpoint_url, key_prefix, storage_location_id, mimetype=None, md5=None, storage_str=None)
async
¶
Use the S3 client to upload a file to an S3 bucket.
Source code in synapseclient/core/upload/upload_functions_async.py
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 |
|
Multipart Upload Async¶
synapseclient.core.upload.multipart_upload_async
¶
Implements the client side of Synapse's Multipart File Upload API, which provides a robust means of uploading large files (into the 10s of GiB). End users should not need to call any of the methods under UploadAttempt directly.
This mermaid flowchart illustrates the process of uploading a file to Synapse using the multipart upload API.
flowchart TD
upload_file_handle --> before-upload
subgraph before-upload
subgraph Disk I/O & CPU
subgraph Multi-Processing
md5["Calculate MD5"]
end
mime["Guess mime type"]
file_size["Get file size"]
file_name["Get file name"]
end
subgraph HTTP
upload_destination["Find where to Upload
GET /entity/{entity_id}/uploadDestination"]
start_upload["Start upload with Synapse
POST /file/multipart"]
presigned_urls["Get URLs to upload to
POST /file/multipart/{upload_id}/presigned/url/batch"]
end
end
before-upload --> during-upload
subgraph during-upload
subgraph multi-threaded["multi-threaded for each part"]
read_part["Read part to upload into Memory"]
read_part --> put_part["HTTP PUT to storage provider"]
subgraph thread_locked1["Lock thread"]
refresh_check{"New URl available?"}
refresh_check --> |no|refresh
refresh["Refresh remaining URLs to upload to
POST /file/multipart/{upload_id}/presigned/url/batch"]
end
put_part --> |URL Expired|refresh_check
refresh_check --> |yes|put_part
refresh --> put_part
put_part --> |Finished|md5_part["Calculate MD5 of part"]
end
complete_part["PUT /file/multipart/{upload_id}/add/{part_number}?partMD5Hex={md5_hex}"]
multi-threaded -->|Upload finished| complete_part
end
during-upload --> post-upload
subgraph post-upload
post_upload_compelete["PUT /file/multipart/{upload_id}/complete"]
get_file_handle["GET /fileHandle/{file_handle_id}"]
end
post-upload --> entity["Create/Update Synapse entity"]
Classes¶
HandlePartResult
dataclass
¶
Result of a part upload.
ATTRIBUTE | DESCRIPTION |
---|---|
part_number |
The part number that was uploaded.
TYPE:
|
part_size |
The size of the part that was uploaded.
TYPE:
|
md5_hex |
The MD5 hash of the part that was uploaded.
TYPE:
|
Source code in synapseclient/core/upload/multipart_upload_async.py
145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
UploadAttemptAsync
¶
Used to handle multi-threaded operations for uploading one or parts of a file.
Source code in synapseclient/core/upload/multipart_upload_async.py
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 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 |
|
Functions¶
shared_progress_bar(progress_bar)
¶
An outside process that will eventually trigger an upload through this module can configure a shared Progress Bar by running its code within this context manager.
Source code in synapseclient/core/upload/multipart_upload_async.py
131 132 133 134 135 136 137 138 139 140 141 142 |
|
multipart_upload_file_async(syn, file_path, dest_file_name=None, content_type=None, part_size=None, storage_location_id=None, preview=True, force_restart=False, md5=None, storage_str=None)
async
¶
Upload a file to a Synapse upload destination in chunks.
PARAMETER | DESCRIPTION |
---|---|
syn |
a Synapse object
TYPE:
|
file_path |
the file to upload
TYPE:
|
dest_file_name |
upload as a different filename
TYPE:
|
content_type |
Refers to the Content-Type of the API request.
TYPE:
|
part_size |
Number of bytes per part. Minimum is 5MiB (5 * 1024 * 1024 bytes).
TYPE:
|
storage_location_id |
an id indicating where the file should be stored. Retrieved from Synapse's UploadDestination
TYPE:
|
preview |
True to generate a preview
TYPE:
|
force_restart |
True to restart a previously initiated upload from scratch, False to try to resume
TYPE:
|
md5 |
The MD5 of the file. If not provided, it will be calculated.
TYPE:
|
storage_str |
Optional string to append to the upload message
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
a File Handle ID |
Keyword arguments are passed down to _multipart_upload().
Source code in synapseclient/core/upload/multipart_upload_async.py
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 |
|
multipart_upload_string_async(syn, text, dest_file_name=None, part_size=None, content_type=None, storage_location_id=None, preview=True, force_restart=False)
async
¶
Upload a file to a Synapse upload destination in chunks.
PARAMETER | DESCRIPTION |
---|---|
syn |
a Synapse object
TYPE:
|
text |
a string to upload as a file.
TYPE:
|
dest_file_name |
upload as a different filename
TYPE:
|
content_type |
Refers to the Content-Type of the API request.
TYPE:
|
part_size |
number of bytes per part. Minimum 5MB.
TYPE:
|
storage_location_id |
an id indicating where the file should be stored. Retrieved from Synapse's UploadDestination
TYPE:
|
preview |
True to generate a preview
TYPE:
|
force_restart |
True to restart a previously initiated upload from scratch, False to try to resume
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
a File Handle ID |
Keyword arguments are passed down to _multipart_upload().
Source code in synapseclient/core/upload/multipart_upload_async.py
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 |
|
multipart_copy_async(syn, source_file_handle_association, dest_file_name=None, part_size=None, storage_location_id=None, preview=True, force_restart=False)
async
¶
Makes a Multipart Upload Copy Request. This request performs a copy of an existing file handle without data transfer from the client.
PARAMETER | DESCRIPTION |
---|---|
syn |
A Synapse object
TYPE:
|
source_file_handle_association |
Describes an association of a FileHandle with another object.
TYPE:
|
dest_file_name |
The name of the file to be uploaded.
TYPE:
|
part_size |
The size that each part will be (in bytes).
TYPE:
|
storage_location_id |
The identifier of the storage location where this file should be copied to. The user must be the owner of the storage location.
TYPE:
|
preview |
True to generate a preview of the data.
TYPE:
|
force_restart |
True to restart a previously initiated upload from scratch, False to try to resume.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
a File Handle ID |
Keyword arguments are passed down to _multipart_upload().
Source code in synapseclient/core/upload/multipart_upload_async.py
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 |
|
Multithreaded Downloading¶
synapseclient.core.multithread_download
¶
Classes¶
DownloadRequest
¶
Bases: NamedTuple
A request to download a file from Synapse
ATTRIBUTE | DESCRIPTION |
---|---|
file_handle_id |
The file handle ID to download.
|
object_id |
The Synapse object this file associated to.
|
object_type |
The type of the associated Synapse object.
|
path |
The local path to download the file to. This path can be either an absolute path or a relative path from where the code is executed to the download location.
|
debug |
A boolean to specify if debug mode is on.
TYPE:
|
Source code in synapseclient/core/multithread_download/download_threads.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
Functions¶
download_file(client, download_request, *, max_concurrent_parts=None)
¶
Main driver for the multi-threaded download. Users an ExecutorService, either set externally onto a thread local by an outside process, or creating one as needed otherwise.
PARAMETER | DESCRIPTION |
---|---|
client |
A synapseclient
|
download_request |
A batch of DownloadRequest objects specifying what Synapse files to download
TYPE:
|
max_concurrent_parts |
The maximum concurrent number parts to download at once when downloading this file
TYPE:
|
Source code in synapseclient/core/multithread_download/download_threads.py
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 |
|
shared_executor(executor)
¶
An outside process that will eventually trigger a download through the this module can configure a shared Executor by running its code within this context manager.
Source code in synapseclient/core/multithread_download/download_threads.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
Download Functions¶
synapseclient.core.download.download_functions
¶
This module handles the various ways that a user can download a file to Synapse.
Classes¶
Functions¶
download_file_entity(download_location, entity, if_collision, submission, *, synapse_client=None)
async
¶
Download file entity
PARAMETER | DESCRIPTION |
---|---|
download_location |
The location on disk where the entity will be downloaded. If
there is a matching file at the location, the download collision will be
handled according to the
TYPE:
|
entity |
The Synapse Entity object
TYPE:
|
if_collision |
Determines how to handle file collisions. May be
TYPE:
|
submission |
Access associated files through a submission rather than through an entity.
TYPE:
|
synapse_client |
If not passed in and caching was not disabled by
TYPE:
|
Source code in synapseclient/core/download/download_functions.py
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 |
|
download_file_entity_model(download_location, file, if_collision, submission, *, synapse_client=None)
async
¶
Download file entity
PARAMETER | DESCRIPTION |
---|---|
download_location |
The location on disk where the entity will be downloaded. If
there is a matching file at the location, the download collision will be
handled according to the
TYPE:
|
entity |
The File object
|
if_collision |
Determines how to handle file collisions. May be
TYPE:
|
submission |
Access associated files through a submission rather than through an entity.
TYPE:
|
synapse_client |
If not passed in and caching was not disabled by
TYPE:
|
Source code in synapseclient/core/download/download_functions.py
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 |
|
download_by_file_handle(file_handle_id, synapse_id, entity_type, destination, retries=5, *, synapse_client=None)
async
¶
Download a file from the given URL to the local file system.
PARAMETER | DESCRIPTION |
---|---|
file_handle_id |
The id of the FileHandle to download
TYPE:
|
synapse_id |
The id of the Synapse object that uses the FileHandle e.g. "syn123"
TYPE:
|
entity_type |
The type of the Synapse object that uses the FileHandle e.g. "FileEntity"
TYPE:
|
destination |
The destination on local file system
TYPE:
|
retries |
The Number of download retries attempted before throwing an exception.
TYPE:
|
synapse_client |
If not passed in and caching was not disabled by
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The path to downloaded file |
sequenceDiagram
title Multi-Threaded Download Process with Retry Mechanism
actor Client as Client
participant download_functions as download_functions
participant download_async as download_async
participant download_execution as download_execution
participant multi_threaded_download as multi_threaded_download
participant remote_storage_server as remote_storage_server
participant file as file
activate Client
Client ->> download_functions: download_by_file_handle
activate download_functions
loop retryable
alt Download type = multi_threaded
note over download_functions: download_from_url_multi_threaded
download_functions ->> download_async: download_file
activate download_async
download_async ->> download_async: _generate_stream_and_write_chunk_tasks
loop for each download task
download_async ->> download_execution: _execute_download_tasks
activate download_execution
par MULTI-THREADED: Run in thread executor
download_execution ->> multi_threaded_download: _stream_and_write_chunk
activate multi_threaded_download
loop stream chunk into memory
multi_threaded_download ->> remote_storage_server: stream chunk from remote server
remote_storage_server -->> multi_threaded_download: Return partial range
end
note over multi_threaded_download: Chunk loaded into memory
alt obtain thread lock [Failed]
note over multi_threaded_download: Wait to obtain lock
else obtain thread lock [Success]
multi_threaded_download ->> file: write chunk to file
file -->> multi_threaded_download: .
note over multi_threaded_download: Update progress bar
note over multi_threaded_download: Release lock
end
multi_threaded_download -->> download_execution: .
end
download_execution -->> download_async: .
note over download_async: Run garbage collection every 100 iterations
deactivate multi_threaded_download
deactivate download_execution
end
download_async -->> download_functions: .
deactivate download_async
download_functions ->> download_functions: md5_for_file
download_functions -->> Client: File downloaded
deactivate download_functions
else Download type = non multi_threaded
note over download_functions: Execute `download_from_url`
else Download type = external s3 object store
note over download_functions: Execute `S3ClientWrapper.download_file`
else Download type = aws s3 sts storage
note over download_functions: Execute `S3ClientWrapper.download_file` with with_boto_sts_credentials
end
end
deactivate Client
Source code in synapseclient/core/download/download_functions.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
|
download_from_url_multi_threaded(file_handle_id, object_id, object_type, destination, *, expected_md5=None, synapse_client=None)
async
¶
Download a file from the given URL using multiple threads.
PARAMETER | DESCRIPTION |
---|---|
file_handle_id |
The id of the FileHandle to download
TYPE:
|
object_id |
The id of the Synapse object that uses the FileHandle e.g. "syn123"
TYPE:
|
object_type |
The type of the Synapse object that uses the FileHandle e.g. "FileEntity". Any of https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/file/FileHandleAssociateType.html
TYPE:
|
destination |
The destination on local file system
TYPE:
|
expected_md5 |
The expected MD5
TYPE:
|
content_size |
The size of the content
|
synapse_client |
If not passed in and caching was not disabled by
TYPE:
|
Raises: SynapseMd5MismatchError: If the actual MD5 does not match expected MD5.
RETURNS | DESCRIPTION |
---|---|
str
|
The path to downloaded file |
Source code in synapseclient/core/download/download_functions.py
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 |
|
download_from_url(url, destination, entity_id, file_handle_associate_type, file_handle_id=None, expected_md5=None, progress_bar=None, *, synapse_client=None)
¶
Download a file from the given URL to the local file system.
PARAMETER | DESCRIPTION |
---|---|
url |
The source of download
TYPE:
|
destination |
The destination on local file system
TYPE:
|
entity_id |
The id of the Synapse object that uses the FileHandle e.g. "syn123"
TYPE:
|
file_handle_associate_type |
The type of the Synapse object that uses the FileHandle e.g. "FileEntity". Any of https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/file/FileHandleAssociateType.html
TYPE:
|
file_handle_id |
Optional. If given, the file will be given a temporary name that includes the file handle id which allows resuming partial downloads of the same file from previous sessions
TYPE:
|
expected_md5 |
Optional. If given, check that the MD5 of the downloaded file matches the expected MD5
TYPE:
|
synapse_client |
If not passed in and caching was not disabled by
TYPE:
|
RAISES | DESCRIPTION |
---|---|
IOError
|
If the local file does not exist. |
SynapseError
|
If fail to download the file. |
SynapseHTTPError
|
If there are too many redirects. |
SynapseMd5MismatchError
|
If the actual MD5 does not match expected MD5. |
RETURNS | DESCRIPTION |
---|---|
Union[str, None]
|
The path to downloaded file or None if the download failed |
Source code in synapseclient/core/download/download_functions.py
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 |
|
is_retryable_download_error(ex)
¶
Check if the download error is retryable
PARAMETER | DESCRIPTION |
---|---|
ex |
An exception
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Boolean value indicating whether the download error is retryable |
Source code in synapseclient/core/download/download_functions.py
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
|
resolve_download_path_collisions(download_location, file_name, if_collision, synapse_cache_location, cached_file_path, *, synapse_client=None)
¶
Resolve file path collisions
PARAMETER | DESCRIPTION |
---|---|
download_location |
The location on disk where the entity will be downloaded. If
there is a matching file at the location, the download collision will be
handled according to the
TYPE:
|
file_name |
The file name
TYPE:
|
if_collision |
Determines how to handle file collisions. May be "overwrite.local", "keep.local", or "keep.both".
TYPE:
|
synapse_cache_location |
The location in .synapseCache where the file would be corresponding to its FileHandleId.
TYPE:
|
cached_file_path |
The file path of the cached copy
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
Invalid ifcollision. Should be "overwrite.local", "keep.local", or "keep.both". |
RETURNS | DESCRIPTION |
---|---|
Union[str, None]
|
The download file path with collisions resolved or None if the file should |
Union[str, None]
|
not be downloaded |
Source code in synapseclient/core/download/download_functions.py
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 |
|
ensure_download_location_is_directory(download_location)
¶
Check if the download location is a directory
PARAMETER | DESCRIPTION |
---|---|
download_location |
The location on disk where the entity will be downloaded.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the download_location is not a directory |
RETURNS | DESCRIPTION |
---|---|
str
|
The download location |
Source code in synapseclient/core/download/download_functions.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 |
|
is_synapse_uri(uri, *, synapse_client=None)
¶
Check whether the given uri is hosted at the configured Synapse repo endpoint
PARAMETER | DESCRIPTION |
---|---|
uri |
A given uri
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
A boolean value indicating whether the given uri is hosted at the configured Synapse repo endpoint |
Source code in synapseclient/core/download/download_functions.py
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
|
Async managed Multithreaded Downloads¶
synapseclient.core.download.download_async
¶
Logic required for the actual transferring of files.
Classes¶
DownloadRequest
¶
Bases: NamedTuple
A request to download a file from Synapse
ATTRIBUTE | DESCRIPTION |
---|---|
file_handle_id |
The file handle ID to download.
|
object_id |
The Synapse object this file associated to.
|
object_type |
The type of the associated Synapse object. Any of https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/file/FileHandleAssociateType.html
|
path |
The local path to download the file to. This path can be either an absolute path or a relative path from where the code is executed to the download location.
|
debug |
A boolean to specify if debug mode is on.
TYPE:
|
Source code in synapseclient/core/download/download_async.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
PresignedUrlInfo
¶
Bases: NamedTuple
Information about a retrieved presigned-url
ATTRIBUTE | DESCRIPTION |
---|---|
file_name |
Name of the file for the presigned url
TYPE:
|
url |
The actual presigned url
TYPE:
|
expiration_utc |
datetime in UTC at which the url will expire
TYPE:
|
Source code in synapseclient/core/download/download_async.py
84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
PresignedUrlProvider
dataclass
¶
Provides an un-exipired pre-signed url to download a file
Source code in synapseclient/core/download/download_async.py
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 |
|
Functions¶
get_info_async()
async
¶
Using async, returns the cached info if it's not expired, otherwise retrieves a new pre-signed url and returns that.
RETURNS | DESCRIPTION |
---|---|
PresignedUrlInfo
|
Information about a retrieved presigned-url from either the cache or a |
PresignedUrlInfo
|
new request |
Source code in synapseclient/core/download/download_async.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
get_info()
¶
Using a thread lock, returns the cached info if it's not expired, otherwise retrieves a new pre-signed url and returns that.
RETURNS | DESCRIPTION |
---|---|
PresignedUrlInfo
|
Information about a retrieved presigned-url from either the cache or a |
PresignedUrlInfo
|
new request |
Source code in synapseclient/core/download/download_async.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
Functions¶
download_file(client, download_request)
async
¶
Main driver for the multi-threaded download. Users an ExecutorService, either set externally onto a thread local by an outside process, or creating one as needed otherwise.
PARAMETER | DESCRIPTION |
---|---|
client |
A synapseclient
TYPE:
|
download_request |
A batch of DownloadRequest objects specifying what Synapse files to download
TYPE:
|
Source code in synapseclient/core/download/download_async.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
Cache¶
synapseclient.core.cache
¶
File Caching
Implements a cache on local disk for Synapse file entities and other objects with a FileHandle. This is part of the internal implementation of the client and should not be accessed directly by users of the client.
Classes¶
Cache
¶
Represent a cache in which files are accessed by file handle ID.
Source code in synapseclient/core/cache.py
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 |
|
Functions¶
contains(file_handle_id, path)
¶
Given a file and file_handle_id, return True if an unmodified cached copy of the file exists at the exact path given or False otherwise.
PARAMETER | DESCRIPTION |
---|---|
file_handle_id |
The ID of the fileHandle
TYPE:
|
path |
The file path at which to look for a cached copy
TYPE:
|
Source code in synapseclient/core/cache.py
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 |
|
get(file_handle_id, path=None)
¶
Retrieve a file with the given file handle from the cache.
PARAMETER | DESCRIPTION |
---|---|
file_handle_id |
The ID of the fileHandle
TYPE:
|
path |
If the given path is None, look for a cached copy of the file in the cache directory. If the path is a directory, look there for a cached copy. If a full file-path is given, only check whether that exact file exists and is unmodified since it was cached.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[str, None]
|
Either a file path, if an unmodified cached copy of the file |
Union[str, None]
|
exists in the specified location or None if it does not |
Source code in synapseclient/core/cache.py
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 |
|
add(file_handle_id, path, md5=None)
¶
Add a file to the cache
Source code in synapseclient/core/cache.py
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 |
|
remove(file_handle_id, path=None, delete=None)
¶
Remove a file from the cache.
PARAMETER | DESCRIPTION |
---|---|
file_handle_id |
Will also extract file handle id from either a File or file handle
TYPE:
|
path |
If the given path is None, remove (and potentially delete) all cached copies. If the path is that of a file in the .cacheMap file, remove it.
TYPE:
|
delete |
If True, delete the file from disk as well as removing it from the cache
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[str]
|
A list of files removed |
Source code in synapseclient/core/cache.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
purge(before_date=None, after_date=None, dry_run=False)
¶
Purge the cache. Use with caution. Deletes files whose cache maps were last updated in a specified period.
Deletes .cacheMap files and files stored in the cache.cache_root_dir, but does not delete files stored outside the cache.
PARAMETER | DESCRIPTION |
---|---|
before_date |
If specified, all files before this date will be removed
TYPE:
|
after_date |
If specified, all files after this date will be removed
TYPE:
|
dry_run |
If dry_run is True, then the selected files are printed rather than removed
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The number of files selected for removal |
Using this function
Either the before_date or after_date must be specified. If both are passed, files between the two dates are selected for removal. Dates must either be a timezone naive Python datetime.datetime instance or the number of seconds since the unix epoch. For example to delete all the files modified in January 2021, either of the following can be used::
using offset naive datetime objects
cache.purge(after_date=datetime.datetime(2021, 1, 1), before_date=datetime.datetime(2021, 2, 1))
using seconds since the unix epoch
cache.purge(after_date=1609459200, before_date=1612137600)
Source code in synapseclient/core/cache.py
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 |
|
Functions¶
epoch_time_to_iso(epoch_time)
¶
Convert seconds since unix epoch to a string in ISO format
Source code in synapseclient/core/cache.py
32 33 34 35 36 37 38 39 40 |
|
iso_time_to_epoch(iso_time)
¶
Convert an ISO formatted time into seconds since unix epoch
Source code in synapseclient/core/cache.py
43 44 45 46 47 48 49 50 51 |
|
compare_timestamps(modified_time, cached_time)
¶
Compare two ISO formatted timestamps, with a special case when cached_time ends in .000Z.
For backward compatibility, we always write .000 for milliseconds into the cache. We then match a cached time ending in .000Z, meaning zero milliseconds with a modified time with any number of milliseconds.
PARAMETER | DESCRIPTION |
---|---|
modified_time |
The float representing seconds since unix epoch
|
cached_time |
The string holding a ISO formatted time
|
Source code in synapseclient/core/cache.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
Credentials¶
synapseclient.core.credentials.cred_data.SynapseCredentials
¶
Bases: AuthBase
, ABC
Source code in synapseclient/core/credentials/cred_data.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
synapseclient.core.credentials.cred_data.SynapseAuthTokenCredentials
¶
Bases: SynapseCredentials
Source code in synapseclient/core/credentials/cred_data.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
synapseclient.core.credentials.credential_provider
¶
This module contains classes that are responsible for retrieving synapse authentication information (e.g. authToken) from a source (e.g. login args, config file).
Classes¶
SynapseCredentialsProvider
¶
A credential provider is responsible for retrieving synapse authentication information (e.g. authToken) from a source (e.g. login args, config file), and use them to return a SynapseCredentials instance.
Source code in synapseclient/core/credentials/credential_provider.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 |
|
Functions¶
get_synapse_credentials(syn, user_login_args)
¶
Returns SynapseCredentials if this provider is able to get valid credentials, returns None otherwise.
PARAMETER | DESCRIPTION |
---|---|
syn |
Synapse client instance
TYPE:
|
user_login_args |
subset of arguments passed during syn.login()
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[SynapseCredentials, None]
|
SynapseCredentials if valid credentials can be found by this provider, None otherwise. |
Source code in synapseclient/core/credentials/credential_provider.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
UserArgsCredentialsProvider
¶
Bases: SynapseCredentialsProvider
Retrieves auth info from user_login_args during a CLI session.
Source code in synapseclient/core/credentials/credential_provider.py
101 102 103 104 105 106 107 108 109 110 111 112 |
|
ConfigFileCredentialsProvider
¶
Bases: SynapseCredentialsProvider
Retrieves auth info from the ~/.synapseConfig
file
Source code in synapseclient/core/credentials/credential_provider.py
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 |
|
AWSParameterStoreCredentialsProvider
¶
Bases: SynapseCredentialsProvider
Retrieves user's authentication token from AWS SSM Parameter store
Source code in synapseclient/core/credentials/credential_provider.py
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 |
|
EnvironmentVariableCredentialsProvider
¶
Bases: SynapseCredentialsProvider
Retrieves the user's authentication token from an environment variable
Source code in synapseclient/core/credentials/credential_provider.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
SynapseCredentialsProviderChain
¶
Bases: object
Class that has a list of SynapseCredentialsProvider from which this class attempts to retrieve SynapseCredentials.
By default this class uses the following providers in this order:
- UserArgsCredentialsProvider
- ConfigFileCredentialsProvider
- EnvironmentVariableCredentialsProvider
- AWSParameterStoreCredentialsProvider
ATTRIBUTE | DESCRIPTION |
---|---|
cred_providers |
list of (SynapseCredentialsProvider) credential providers
|
Source code in synapseclient/core/credentials/credential_provider.py
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 |
|
Functions¶
get_credentials(syn, user_login_args)
¶
Iterates its list of SynapseCredentialsProvider and returns the first non-None SynapseCredentials returned by a provider. If no provider is able to provide a SynapseCredentials, returns None.
PARAMETER | DESCRIPTION |
---|---|
syn |
Synapse client instance
TYPE:
|
user_login_args |
subset of arguments passed during syn.login()
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[SynapseCredentials, None]
|
SynapseCredentials returned by the first non-None provider in its list, None otherwise |
Source code in synapseclient/core/credentials/credential_provider.py
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 |
|
Functions¶
get_default_credential_chain()
¶
Creates and uses a default credential chain to retrieve SynapseCredentials. The order this is returned is the order in which the credential providers are attempted.
RETURNS | DESCRIPTION |
---|---|
SynapseCredentialsProviderChain
|
credential chain |
Source code in synapseclient/core/credentials/credential_provider.py
270 271 272 273 274 275 276 277 278 279 280 |
|
Remote File Storage Wrappers¶
synapseclient.core.remote_file_storage_wrappers
¶
Wrappers for remote file storage clients like S3 and SFTP.
Classes¶
S3ClientWrapper
¶
Wrapper class for S3 client.
Source code in synapseclient/core/remote_file_storage_wrappers.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 |
|
Functions¶
download_file(bucket, endpoint_url, remote_file_key, download_file_path, *, profile_name=None, credentials=None, progress_bar=None, transfer_config_kwargs=None)
staticmethod
¶
Download a file from s3 using boto3.
PARAMETER | DESCRIPTION |
---|---|
bucket |
name of bucket to upload to
TYPE:
|
endpoint_url |
a boto3 compatible endpoint url
TYPE:
|
remote_file_key |
object key to upload the file to
TYPE:
|
download_file_path |
local path to save the file to
TYPE:
|
profile_name |
AWS profile name from local aws config, mutually exclusive with credentials
TYPE:
|
credentials |
a dictionary of AWS credentials to use, mutually exclusive with profile_name Expected items:
TYPE:
|
progress_bar |
The progress bar to update. Defaults to None.
TYPE:
|
transfer_config_kwargs |
boto S3 transfer configuration (see boto3.s3.transfer.TransferConfig)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
download_file_path
|
S3 path of the file
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the key does not exist in the bucket. |
ClientError
|
If there is an error with the S3 client. |
Source code in synapseclient/core/remote_file_storage_wrappers.py
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 |
|
upload_file(bucket, endpoint_url, remote_file_key, upload_file_path, *, profile_name=None, credentials=None, show_progress=True, transfer_config_kwargs=None, storage_str=None)
staticmethod
¶
Upload a file to s3 using boto3.
PARAMETER | DESCRIPTION |
---|---|
bucket |
name of bucket to upload to
TYPE:
|
endpoint_url |
a boto3 compatible endpoint url
TYPE:
|
remote_file_key |
object key to upload the file to
TYPE:
|
upload_file_path |
local path of the file to upload
TYPE:
|
profile_name |
AWS profile name from local aws config, mutually exclusive with credentials
TYPE:
|
credentials |
a dictionary of AWS credentials to use, mutually exclusive with profile_name Expected items:
TYPE:
|
show_progress |
whether to print progress indicator to console
TYPE:
|
transfer_config_kwargs |
boto S3 transfer configuration (see boto3.s3.transfer.TransferConfig)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
upload_file_path
|
S3 path of the file
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the path does not exist or is not a file |
ClientError
|
If there is an error with the S3 client. |
Source code in synapseclient/core/remote_file_storage_wrappers.py
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 |
|
SFTPWrapper
¶
Source code in synapseclient/core/remote_file_storage_wrappers.py
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 |
|
Functions¶
upload_file(filepath, url, username=None, password=None, storage_str=None)
staticmethod
¶
Performs upload of a local file to an sftp server.
PARAMETER | DESCRIPTION |
---|---|
filepath |
The path to the file to be uploaded.
TYPE:
|
url |
URL where file will be deposited. Should include path and protocol. e.g. sftp://sftp.example.com/path/to/file/store
TYPE:
|
username |
The username for authentication. Defaults to None.
TYPE:
|
password |
The password for authentication. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The URL of the uploaded file. |
Source code in synapseclient/core/remote_file_storage_wrappers.py
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 |
|
download_file(url, localFilepath=None, username=None, password=None, progress_bar=None)
staticmethod
¶
Performs download of a file from an sftp server.
PARAMETER | DESCRIPTION |
---|---|
url |
URL where file will be deposited. Path will be chopped out.
TYPE:
|
localFilepath |
location where to store file
TYPE:
|
username |
username on server
TYPE:
|
password |
password for authentication on server
TYPE:
|
progress_bar |
The progress bar to update. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The local filepath where the file was saved. |
Source code in synapseclient/core/remote_file_storage_wrappers.py
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 |
|
Functions¶
Retry¶
synapseclient.core.retry
¶
A helper tool that allows the Python client to make more than one attempt at connecting to the server if initially met with an error. These retry attempts can be made under certain conditions, i.e. for certain status codes, connection errors, and/or connection exceptions.
Functions¶
with_retry(function, verbose=False, retry_status_codes=[429, 500, 502, 503, 504], expected_status_codes=[], retry_errors=[], retry_exceptions=[], retries=DEFAULT_RETRIES, wait=DEFAULT_WAIT, back_off=DEFAULT_BACK_OFF, max_wait=DEFAULT_MAX_WAIT)
¶
Retries the given function under certain conditions.
PARAMETER | DESCRIPTION |
---|---|
function |
A function with no arguments. If arguments are needed, use a lambda (see example).
|
retry_status_codes |
What status codes to retry upon in the case of a SynapseHTTPError.
DEFAULT:
|
expected_status_codes |
If specified responses with any other status codes result in a retry.
DEFAULT:
|
retry_errors |
What reasons to retry upon, if function().response.json()['reason'] exists.
DEFAULT:
|
retry_exceptions |
What types of exceptions, specified as strings or Exception classes, to retry upon.
DEFAULT:
|
retries |
How many times to retry maximum.
DEFAULT:
|
wait |
How many seconds to wait between retries.
DEFAULT:
|
back_off |
Exponential constant to increase wait for between progressive failures.
DEFAULT:
|
max_wait |
back_off between requests will not exceed this value
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
function() |
Using with_retry
Using with_retry
to consolidate inputs into a list.
from synapseclient.core.retry import with_retry
def foo(a, b, c): return [a, b, c]
result = with_retry(lambda: foo("1", "2", "3"), **STANDARD_RETRY_PARAMS)
Source code in synapseclient/core/retry.py
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 |
|
calculate_exponential_backoff(retries, base_wait, wait_random_lower, wait_random_upper, back_off_factor, max_back_off)
¶
Handle calculating the exponential backoff.
PARAMETER | DESCRIPTION |
---|---|
retries |
The number of retries that have been attempted
TYPE:
|
base_wait |
The base wait time
TYPE:
|
wait_random_lower |
The lower bound of the random wait time
TYPE:
|
wait_random_upper |
The upper bound of the random wait time
TYPE:
|
back_off_factor |
The factor to increase the wait time by for each retry
TYPE:
|
max_back_off |
The maximum wait time
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The total wait time |
Source code in synapseclient/core/retry.py
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 |
|
with_retry_time_based_async(function, verbose=False, retry_status_codes=None, expected_status_codes=None, retry_errors=None, retry_exceptions=None, retry_base_wait=DEFAULT_BASE_WAIT_ASYNC, retry_wait_random_lower=DEFAULT_WAIT_RANDOM_LOWER_ASYNC, retry_wait_random_upper=DEFAULT_WAIT_RANDOM_UPPER_ASYNC, retry_back_off_factor=DEFAULT_BACK_OFF_FACTOR_ASYNC, retry_max_back_off=DEFAULT_MAX_BACK_OFF_ASYNC, retry_max_wait_before_failure=DEFAULT_MAX_WAIT_BEFORE_FAIL_ASYNC, read_response_content=True)
async
¶
Retries the given function under certain conditions. This is created such that it
will retry an unbounded number of times until the maximum wait time is reached. The
backoff is calculated using an exponential backoff algorithm with a random jitter.
The maximum backoff inbetween retries is capped at retry_max_back_off
.
PARAMETER | DESCRIPTION |
---|---|
verbose |
Whether to log debug messages
TYPE:
|
function |
A function with no arguments. If arguments are needed, use a lambda (see example).
TYPE:
|
retry_status_codes |
What status codes to retry upon in the case of a SynapseHTTPError.
TYPE:
|
expected_status_codes |
If specified responses with any other status codes result in a retry.
TYPE:
|
retry_errors |
What reasons to retry upon, if
TYPE:
|
retry_exceptions |
What types of exceptions, specified as strings or Exception classes, to retry upon.
TYPE:
|
retry_base_wait |
The base wait time inbetween retries.
TYPE:
|
retry_wait_random_lower |
The lower bound of the random wait time.
TYPE:
|
retry_wait_random_upper |
The upper bound of the random wait time.
TYPE:
|
retry_back_off_factor |
The factor to increase the wait time by for each retry.
TYPE:
|
retry_max_back_off |
The maximum wait time.
TYPE:
|
retry_max_wait_before_failure |
The maximum wait time before failure.
TYPE:
|
read_response_content |
Whether to read the response content for HTTP requests.
TYPE:
|
Using with_retry
Using with_retry_time_based_async
to consolidate inputs into a list.
from synapseclient.core.retry import with_retry_time_based_async
async def foo(a, b, c): return [a, b, c]
result = await with_retry_time_based_async(lambda: foo("1", "2", "3"))
Source code in synapseclient/core/retry.py
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 |
|
with_retry_time_based(function, verbose=False, retry_status_codes=None, expected_status_codes=None, retry_errors=None, retry_exceptions=None, retry_base_wait=DEFAULT_BASE_WAIT_ASYNC, retry_wait_random_lower=DEFAULT_WAIT_RANDOM_LOWER_ASYNC, retry_wait_random_upper=DEFAULT_WAIT_RANDOM_UPPER_ASYNC, retry_back_off_factor=DEFAULT_BACK_OFF_FACTOR_ASYNC, retry_max_back_off=DEFAULT_MAX_BACK_OFF_ASYNC, retry_max_wait_before_failure=DEFAULT_MAX_WAIT_BEFORE_FAIL_ASYNC, read_response_content=True)
¶
Retries the given function under certain conditions. This is created such that it
will retry an unbounded number of times until the maximum wait time is reached. The
backoff is calculated using an exponential backoff algorithm with a random jitter.
The maximum backoff inbetween retries is capped at retry_max_back_off
.
PARAMETER | DESCRIPTION |
---|---|
verbose |
Whether to log debug messages
TYPE:
|
function |
A function with no arguments. If arguments are needed, use a lambda (see example).
|
retry_status_codes |
What status codes to retry upon in the case of a SynapseHTTPError.
TYPE:
|
expected_status_codes |
If specified responses with any other status codes result in a retry.
TYPE:
|
retry_errors |
What reasons to retry upon, if
TYPE:
|
retry_exceptions |
What types of exceptions, specified as strings or Exception classes, to retry upon.
TYPE:
|
retry_base_wait |
The base wait time inbetween retries.
TYPE:
|
retry_wait_random_lower |
The lower bound of the random wait time.
TYPE:
|
retry_wait_random_upper |
The upper bound of the random wait time.
TYPE:
|
retry_back_off_factor |
The factor to increase the wait time by for each retry.
TYPE:
|
retry_max_back_off |
The maximum wait time.
TYPE:
|
retry_max_wait_before_failure |
The maximum wait time before failure.
TYPE:
|
read_response_content |
Whether to read the response content for HTTP requests.
TYPE:
|
Using with_retry
Using with_retry_time_based
to consolidate inputs into a list.
from synapseclient.core.retry import with_retry_time_based
async def foo(a, b, c): return [a, b, c]
result = with_retry_time_based(lambda: foo("1", "2", "3"))
Source code in synapseclient/core/retry.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 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 |
|
Utils¶
synapseclient.core.utils
¶
Utility functions useful in the implementation and testing of the Synapse client.
Classes¶
threadsafe_iter
¶
Takes an iterator/generator and makes it thread-safe by serializing call to the
next
method of given iterator/generator.
See: http://anandology.com/blog/using-iterators-and-generators/
Source code in synapseclient/core/utils.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
|
deprecated_keyword_param
¶
A decorator to use to warn when a keyword parameter from a function has been deprecated and is intended for future removal. Will emit a warning such a keyword is passed.
Source code in synapseclient/core/utils.py
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 |
|
Functions¶
md5_for_file(filename, block_size=2 * MB, callback=None)
¶
Calculates the MD5 of the given file. See source http://stackoverflow.com/questions/1131220/get-md5-hash-of-a-files-without-open-it-in-python.
PARAMETER | DESCRIPTION |
---|---|
filename |
The file to read in
TYPE:
|
block_size |
How much of the file to read in at once (bytes). Defaults to 2 MB
TYPE:
|
callback |
The callback function that help us show loading spinner on terminal. Defaults to None
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
The MD5 Checksum |
Source code in synapseclient/core/utils.py
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 |
|
md5_for_file_hex(filename, block_size=2 * MB, callback=None)
¶
Calculates the MD5 of the given file. See source http://stackoverflow.com/questions/1131220/get-md5-hash-of-a-files-without-open-it-in-python.
PARAMETER | DESCRIPTION |
---|---|
filename |
The file to read in
TYPE:
|
block_size |
How much of the file to read in at once (bytes). Defaults to 2 MB
TYPE:
|
callback |
The callback function that help us show loading spinner on terminal. Defaults to None
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The MD5 Checksum |
Source code in synapseclient/core/utils.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
md5_fn(part, _)
¶
Calculate the MD5 of a file-like object.
PARAMETER | DESCRIPTION |
---|---|
part |
A file-like object to read from.
|
RETURNS | DESCRIPTION |
---|---|
str
|
The MD5 Checksum |
Source code in synapseclient/core/utils.py
114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
download_file(url, localFilepath=None)
¶
Downloads a remote file.
PARAMETER | DESCRIPTION |
---|---|
localFilePath |
May be None, in which case a temporary file is created
|
RETURNS | DESCRIPTION |
---|---|
localFilePath
|
The path to the downloaded file
TYPE:
|
Source code in synapseclient/core/utils.py
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 |
|
extract_filename(content_disposition_header, default_filename=None)
¶
Extract a filename from an HTTP content-disposition header field.
See this memo and this package for cryptic details.
Source code in synapseclient/core/utils.py
165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
extract_user_name(profile)
¶
Extract a displayable user name from a user's profile
Source code in synapseclient/core/utils.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
id_of(obj)
¶
Try to figure out the Synapse ID of the given object.
PARAMETER | DESCRIPTION |
---|---|
obj |
May be a string, Entity object, or dictionary
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The ID |
RAISES | DESCRIPTION |
---|---|
ValueError
|
if the object doesn't have an ID |
Source code in synapseclient/core/utils.py
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 |
|
validate_submission_id(submission_id)
¶
Ensures that a given submission ID is either an integer or a string that can be converted to an integer. Version notation is not supported for submission IDs, therefore decimals are not allowed.
PARAMETER | DESCRIPTION |
---|---|
submission_id |
The submission ID to validate
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The submission ID as a string |
Source code in synapseclient/core/utils.py
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 |
|
concrete_type_of(obj)
¶
Return the concrete type of an object representing a Synapse entity. This is meant to operate either against an actual Entity object, or the lighter weight dictionary returned by Synapse#getChildren, both of which are Mappings.
Source code in synapseclient/core/utils.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
is_in_path(id, path)
¶
Determines whether id is in the path as returned from /entity/{id}/path
PARAMETER | DESCRIPTION |
---|---|
id |
synapse id string
TYPE:
|
path |
object as returned from '/entity/{id}/path'
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True or False |
Source code in synapseclient/core/utils.py
310 311 312 313 314 315 316 317 318 319 320 |
|
get_properties(entity)
¶
Returns the dictionary of properties of the given Entity.
Source code in synapseclient/core/utils.py
323 324 325 326 |
|
is_url(s)
¶
Return True if the string appears to be a valid URL.
Source code in synapseclient/core/utils.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
as_url(s)
¶
Tries to convert the input into a proper URL.
Source code in synapseclient/core/utils.py
345 346 347 348 349 350 351 352 353 354 |
|
guess_file_name(string)
¶
Tries to derive a filename from an arbitrary string.
Source code in synapseclient/core/utils.py
357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
normalize_path(path)
¶
Transforms a path into an absolute path with forward slashes only.
Source code in synapseclient/core/utils.py
372 373 374 375 376 |
|
equal_paths(path1, path2)
¶
Compare file paths in a platform neutral way
Source code in synapseclient/core/utils.py
379 380 381 382 383 |
|
file_url_to_path(url, verify_exists=False)
¶
Convert a file URL to a path, handling some odd cases around Windows paths.
PARAMETER | DESCRIPTION |
---|---|
url |
a file URL
TYPE:
|
verify_exists |
If true, return an populated dict only if the resulting file path exists on the local file system.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[str, None]
|
a path or None if the URL is not a file URL. |
Source code in synapseclient/core/utils.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
is_same_base_url(url1, url2)
¶
Compares two urls to see if they are the same excluding up to the base path
PARAMETER | DESCRIPTION |
---|---|
url1 |
a URL
TYPE:
|
url2 |
a second URL
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
A Boolean |
Source code in synapseclient/core/utils.py
412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
is_synapse_id_str(obj)
¶
If the input is a Synapse ID return it, otherwise return None
Source code in synapseclient/core/utils.py
427 428 429 430 431 432 433 |
|
get_synid_and_version(obj)
¶
Extract the Synapse ID and version number from input entity
PARAMETER | DESCRIPTION |
---|---|
obj |
May be a string, Entity object, or dictionary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str, Union[int, None]]
|
A tuple containing the synapse ID and version number, where the version number may be an integer or None if the input object does not contain a versonNumber or .version notation (if string). |
Get synID and version from string object
Extract the synID and version number of the entity string ID
from synapseclient.core import utils
utils.get_synid_and_version("syn123.4")
The call above will return the following tuple:
('syn123', 4)
Source code in synapseclient/core/utils.py
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 |
|
bool_or_none(input_value)
¶
Attempts to convert a string to a bool. Returns None if it fails.
PARAMETER | DESCRIPTION |
---|---|
input_value |
The string to convert to a bool
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[bool, None]
|
The bool or None if the conversion fails |
Source code in synapseclient/core/utils.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
datetime_or_none(datetime_str)
¶
Attempts to convert a string to a datetime object. Returns None if it fails.
Some of the expected formats of datetime_str are:
- 2023-12-04T07:00:00Z
- 2001-01-01 15:00:00+07:00
- 2001-01-01 15:00:00-07:00
- 2023-12-04 07:00:00+00:00
- 2019-01-01
PARAMETER | DESCRIPTION |
---|---|
datetime_str |
The string to convert to a datetime object
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[datetime, None]
|
The datetime object or None if the conversion fails |
Source code in synapseclient/core/utils.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
is_date(dt)
¶
Objects of class datetime.date and datetime.datetime will be recognized as dates
Source code in synapseclient/core/utils.py
525 526 527 |
|
to_list(value)
¶
Convert the value (an iterable or a scalar value) to a list.
Source code in synapseclient/core/utils.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
make_bogus_uuid_file()
¶
Makes a bogus test file with a uuid4 string for testing. It is the caller's responsibility to clean up the file when finished.
RETURNS | DESCRIPTION |
---|---|
str
|
The name of the file |
Source code in synapseclient/core/utils.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
|
make_bogus_data_file(n=100, seed=None)
¶
Makes a bogus data file for testing. It is the caller's responsibility to clean up the file when finished.
PARAMETER | DESCRIPTION |
---|---|
n |
How many random floating point numbers to be written into the file, separated by commas
TYPE:
|
seed |
Random seed for the random numbers
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The name of the file |
Source code in synapseclient/core/utils.py
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 |
|
make_bogus_binary_file(n=1 * KB, filepath=None, printprogress=False)
¶
Makes a bogus binary data file for testing. It is the caller's responsibility to clean up the file when finished.
PARAMETER | DESCRIPTION |
---|---|
n |
How many bytes to write
TYPE:
|
filepath |
Where to write the data
TYPE:
|
printprogress |
Toggle printing of progress
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The name of the file |
Source code in synapseclient/core/utils.py
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 |
|
to_unix_epoch_time(dt)
¶
Convert either datetime.date or datetime.datetime objects to UNIX time.
Source code in synapseclient/core/utils.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
to_unix_epoch_time_secs(dt)
¶
Convert either datetime.date or datetime.datetime objects to UNIX time.
Source code in synapseclient/core/utils.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
|
from_unix_epoch_time_secs(secs)
¶
Returns a Datetime object given milliseconds since midnight Jan 1, 1970.
Source code in synapseclient/core/utils.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
from_unix_epoch_time(ms)
¶
Returns a Datetime object given milliseconds since midnight Jan 1, 1970.
Source code in synapseclient/core/utils.py
705 706 707 708 709 710 |
|
datetime_to_iso(dt, sep='T', include_milliseconds_if_zero=True)
¶
Round microseconds to milliseconds (as expected by older clients) and add back the "Z" at the end. See: http://stackoverflow.com/questions/30266188/how-to-convert-date-string-to-iso8601-standard
PARAMETER | DESCRIPTION |
---|---|
dt |
The datetime to convert
TYPE:
|
sep |
Seperator character to use.
TYPE:
|
include_milliseconds_if_zero |
Whether or not to include millseconds in this result if the number of millseconds is 0.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The formatted string. |
Source code in synapseclient/core/utils.py
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 |
|
format_time_interval(seconds)
¶
Format a time interval given in seconds to a readable value, e.g. "5 minutes, 37 seconds".
Source code in synapseclient/core/utils.py
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 |
|
itersubclasses(cls, _seen=None)
¶
http://code.activestate.com/recipes/576949/ (r3)
itersubclasses(cls)
Generator over all subclasses of a given class, in depth first order.
>>> list(itersubclasses(int)) == [bool]
True
>>> class A(object): pass
>>> class B(A): pass
>>> class C(A): pass
>>> class D(B,C): pass
>>> class E(D): pass
>>>
>>> for cls in itersubclasses(A):
... print(cls.__name__)
B
D
E
C
>>> # get ALL (new-style) classes currently defined
>>> [cls.__name__ for cls in itersubclasses(object)] #doctest: +ELLIPSIS
['type', ...'tuple', ...]
Source code in synapseclient/core/utils.py
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 |
|
normalize_whitespace(s)
¶
Strips the string and replace all whitespace sequences and other non-printable characters with a single space.
Source code in synapseclient/core/utils.py
835 836 837 838 839 840 841 |
|
query_limit_and_offset(query, hard_limit=1000)
¶
Extract limit and offset from the end of a query string.
RETURNS | DESCRIPTION |
---|---|
str
|
A tuple containing the query with limit and offset removed, |
int
|
the limit at most equal to the hard_limit, |
int
|
and the offset which defaults to 1 |
Source code in synapseclient/core/utils.py
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 |
|
extract_synapse_id_from_query(query)
¶
An unfortunate hack to pull the synapse ID out of a table query of the form "select column1, column2 from syn12345 where...." needed to build URLs for table services.
Source code in synapseclient/core/utils.py
940 941 942 943 944 945 946 947 948 949 950 |
|
printTransferProgress(transferred, toBeTransferred, prefix='', postfix='', isBytes=True, dt=None, previouslyTransferred=0)
¶
Prints a progress bar
PARAMETER | DESCRIPTION |
---|---|
transferred |
a number of items/bytes completed
TYPE:
|
toBeTransferred |
total number of items/bytes when completed
TYPE:
|
prefix |
String printed before progress bar
TYPE:
|
postfix |
String printed after progress bar
TYPE:
|
isBytes |
A boolean indicating whether to convert bytes to kB, MB, GB etc.
TYPE:
|
dt |
The time in seconds that has passed since transfer started is used to calculate rate
TYPE:
|
previouslyTransferred |
the number of bytes that were already transferred before this transfer began (e.g. someone ctrl+c'd out of an upload and restarted it later)
TYPE:
|
Source code in synapseclient/core/utils.py
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 |
|
touch(path, times=None)
¶
Make sure a file exists. Update its access and modified times.
Source code in synapseclient/core/utils.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 |
|
is_json(content_type)
¶
detect if a content-type is JSON
Source code in synapseclient/core/utils.py
1053 1054 1055 1056 1057 1058 1059 1060 1061 |
|
find_data_file_handle(bundle)
¶
Return the fileHandle whose ID matches the dataFileHandleId in an entity bundle
Source code in synapseclient/core/utils.py
1064 1065 1066 1067 1068 1069 |
|
unique_filename(path)
¶
Returns a unique path by appending (n) for some number n to the end of the filename.
Source code in synapseclient/core/utils.py
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 |
|
threadsafe_generator(f)
¶
A decorator that takes a generator function and makes it thread-safe. See: http://anandology.com/blog/using-iterators-and-generators/
Source code in synapseclient/core/utils.py
1102 1103 1104 1105 1106 1107 1108 1109 1110 |
|
extract_prefix(keys)
¶
Takes a list of strings and extracts a common prefix delimited by a dot, for example::
extract_prefix(["entity.bang", "entity.bar", "entity.bat"])
# returns "entity"
Source code in synapseclient/core/utils.py
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
|
extract_zip_file_to_directory(zip_file, zip_entry_name, target_dir)
¶
Extracts a specified file in a zip to the specified directory
PARAMETER | DESCRIPTION |
---|---|
zip_file |
an opened zip file. e.g. "with zipfile.ZipFile(zipfilepath) as zip_file:"
TYPE:
|
zip_entry_name |
the name of the file to be extracted from the zip e.g. folderInsideZipIfAny/fileName.txt
TYPE:
|
target_dir |
the directory to which the file will be extracted
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
full path to the extracted file |
Source code in synapseclient/core/utils.py
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 |
|
topolgical_sort(graph)
¶
Given a graph in the form of a dictionary returns a sorted list Adapted from: http://blog.jupo.org/2012/04/06/topological-sorting-acyclic-directed-graphs/
PARAMETER | DESCRIPTION |
---|---|
graph |
a dictionary with values containing lists of keys
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
A sorted list of items |
Source code in synapseclient/core/utils.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 |
|
caller_module_name(current_frame)
¶
Returns the name of the module in which the calling function resides.
PARAMETER | DESCRIPTION |
---|---|
current_frame |
use inspect.currentframe().
|
RETURNS | DESCRIPTION |
---|---|
the name of the module calling the function, foo(), |
|
in which this calling_module() is invoked. |
|
Ignores callers that belong in the same module as foo() |
Source code in synapseclient/core/utils.py
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 |
|
attempt_import(module_name, fail_message)
¶
Attempt to import a module by name and return the imported module if successful.
PARAMETER | DESCRIPTION |
---|---|
module_name |
The name of the module to import.
TYPE:
|
fail_message |
The error message to display if the import fails.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
The imported module. |
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the module cannot be imported. |
Source code in synapseclient/core/utils.py
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 |
|
snake_case(string)
¶
Convert the given string from CamelCase to snake_case
Source code in synapseclient/core/utils.py
1308 1309 1310 1311 |
|
is_base64_encoded(input_string)
¶
Return whether the given input string appears to be base64 encoded
Source code in synapseclient/core/utils.py
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
|
delete_none_keys(incoming_object)
¶
Clean up the incoming object by removing any keys with None values.
Source code in synapseclient/core/utils.py
1370 1371 1372 1373 1374 1375 |
|
merge_dataclass_entities(source, destination, fields_to_ignore=None)
¶
Utility function to merge two dataclass entities together. This is used when we are upserting an entity from the Synapse service with the requested changes.
PARAMETER | DESCRIPTION |
---|---|
source |
The source entity to merge from. |
destination |
The destination entity to merge into. |
fields_to_ignore |
A list of fields to ignore when merging.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Project, Folder, File]
|
The destination entity with the merged values. |
Source code in synapseclient/core/utils.py
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 |
|
Async Utils¶
synapseclient.core.async_utils
¶
This utility class is to hold any utilities that are needed for async operations.
Classes¶
ClassOrInstance
¶
Helper class to allow a method to be called as a class method or instance method.
Source code in synapseclient/core/async_utils.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
Functions¶
otel_trace_method(method_to_trace_name=None)
¶
Decorator to trace a method with OpenTelemetry in an async environment. This function is specifically written to be used on a method within a class.
This will pass the class instance as the first argument to the method. This allows you to modify the name of the trace to include information about the class instance.
Decorating a method within a class that will be traced with OpenTelemetry.
Setting the trace name:
@otel_trace_method(method_to_trace_name=lambda self, **kwargs: f"Project_Store: {self.name}")
async def store(self):
PARAMETER | DESCRIPTION |
---|---|
method_to_trace_name |
A callable that takes the class instance as the first argument and returns a string to be used as the trace name. If this is not provided, the trace name will be set to the method name.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
A callable decorator that will trace the method with OpenTelemetry. |
Source code in synapseclient/core/async_utils.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
wrap_async_to_sync(coroutine, syn)
¶
Wrap an async function to be called in a sync context.
Source code in synapseclient/core/async_utils.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
async_to_sync(cls)
¶
Convert all name_of_thing_async methods to name_of_thing methods
(see http://stackoverflow.com/questions/18048341/add-methods-to-a-class-generated-from-other-methods for help understanding)
Source code in synapseclient/core/async_utils.py
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 |
|
Versions¶
synapseclient.core.version_check
¶
Version Functions¶
Check for latest version and recommend upgrade:
synapseclient.check_for_updates()
Print release notes for installed version of client:
synapseclient.release_notes()
Functions¶
version_check(current_version=None, version_url=_VERSION_URL, check_for_point_releases=False)
¶
Gets the latest version information from version_url and check against the current version. Recommends upgrade, if a newer version exists.
PARAMETER | DESCRIPTION |
---|---|
current_version |
The current version of the entity
DEFAULT:
|
version_url |
The URL of the entity version
DEFAULT:
|
check_for_point_releases |
Bool.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
True if current version is the latest release (or higher) version, otherwise False. |
Source code in synapseclient/core/version_check.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
check_for_updates()
¶
Check for the existence of newer versions of the client, reporting both current release version and development version.
For help installing development versions of the client, see the README.md.
Source code in synapseclient/core/version_check.py
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 |
|
release_notes(version_url=None)
¶
Print release notes for the installed version of the client or latest release or development version if version_url is supplied.
Defaults to None, meaning release notes for the installed version. Alternatives are:
- synapseclient.version_check._VERSION_URL
- synapseclient.version_check._DEV_VERSION_URL
Source code in synapseclient/core/version_check.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
STS Transfer¶
synapseclient.core.sts_transfer
¶
Classes¶
StsTokenStore
¶
Cache STS tokens in memory for observed entity ids. An optimization for long lived Synapse objects that will interact with the same Synapse storage locations over and over again so they don't have to do a remote call to fetch a new token for every entity, which for e.g. small files can amount to non trivial overhead.
Source code in synapseclient/core/sts_transfer.py
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 |
|
Functions¶
get_sts_credentials(syn, entity_id, permission, *, output_format='json', min_remaining_life=None)
¶
See Synapse.get_sts_storage_token
Source code in synapseclient/core/sts_transfer.py
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 |
|
with_boto_sts_credentials(fn, syn, entity_id, permission)
¶
A wrapper around a function that will get sts credentials and try to use them on the given
function which should take a dictionary with the aws_access_key_id
, aws_secret_access_key
, and aws_session_token
as keys. If the given function returns a boto error that looks like the token has expired
it will retry once after fetching fresh credentials.
The purpose is to be able to use potentially cached credentials in long running tasks while reducing worry that they will expire in the middle of running and cause an unrecoverable error. The alternative of fetching a fresh STS token for every request might be okay for a few large files but would greatly slow down transferring many small files.
Source code in synapseclient/core/sts_transfer.py
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 |
|
is_boto_sts_transfer_enabled(syn)
¶
Check if the boto/STS transfers are enabled in the Synapse configuration. If enabled then synapseclient will attempt to automatically use boto to upload and download from supported storage locations that are sts enabled.
PARAMETER | DESCRIPTION |
---|---|
syn |
A Synapse object
|
RETURNS | DESCRIPTION |
---|---|
True if STS if enabled, False otherwise |
Source code in synapseclient/core/sts_transfer.py
221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
is_storage_location_sts_enabled(syn, entity_id, location)
¶
Returns whether the given storage location is enabled for STS.
PARAMETER | DESCRIPTION |
---|---|
syn |
A Synapse object
|
entity_id |
The ID of synapse entity whose storage location we want to check for sts access
|
location |
A storage location ID or a dictionary representing the location UploadDestination
|
RETURNS | DESCRIPTION |
---|---|
True if STS is enabled for the location, False otherwise |
Source code in synapseclient/core/sts_transfer.py
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 |
|
is_storage_location_sts_enabled_async(syn, entity_id, location)
async
¶
Returns whether the given storage location is enabled for STS.
PARAMETER | DESCRIPTION |
---|---|
syn |
A Synapse object
TYPE:
|
entity_id |
The ID of synapse entity whose storage location we want to check for sts access
TYPE:
|
location |
A storage location ID or a dictionary representing the location UploadDestination
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if STS is enabled for the location, False otherwise |
Source code in synapseclient/core/sts_transfer.py
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 |
|