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
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 |
|
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
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 |
|
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
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 |
|
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
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
|
_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
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 |
|
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
146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
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
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 605 606 607 608 609 610 611 612 |
|
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
132 133 134 135 136 137 138 139 140 141 142 143 |
|
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
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
|
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
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 |
|
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
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 |
|
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 or None this will use the last client from
the
TYPE:
|
Source code in synapseclient/core/download/download_functions.py
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 |
|
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 or None this will use the last client from
the
TYPE:
|
Source code in synapseclient/core/download/download_functions.py
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 |
|
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 or None this will use the last client from
the
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
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 |
|
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 or None this will use the last client from
the
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
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
|
download_from_url(url, destination, 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:
|
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 or None this will use the last client from
the
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
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 |
|
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
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 |
|
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
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
|
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
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 |
|
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
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
|
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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
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
86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
PresignedUrlProvider
dataclass
¶
Provides an un-exipired pre-signed url to download a file
Source code in synapseclient/core/download/download_async.py
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 |
|
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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
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 |
|
synapseclient.core.credentials.cred_data.SynapseAuthTokenCredentials
¶
Bases: SynapseCredentials
Source code in synapseclient/core/credentials/cred_data.py
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 |
|
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 |
|
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
100 101 102 103 104 105 106 107 108 109 110 111 |
|
ConfigFileCredentialsProvider
¶
Bases: SynapseCredentialsProvider
Retrieves auth info from the ~/.synapseConfig
file
Source code in synapseclient/core/credentials/credential_provider.py
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 |
|
AWSParameterStoreCredentialsProvider
¶
Bases: SynapseCredentialsProvider
Retrieves user's authentication token from AWS SSM Parameter store
Source code in synapseclient/core/credentials/credential_provider.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
EnvironmentVariableCredentialsProvider
¶
Bases: SynapseCredentialsProvider
Retrieves the user's authentication token from an environment variable
Source code in synapseclient/core/credentials/credential_provider.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
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
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 |
|
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
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 |
|
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
269 270 271 272 273 274 275 276 277 278 279 |
|
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 |
|