Last active
July 20, 2023 15:52
-
-
Save wy193777/e7607d12fad13459e8992d4f69b53586 to your computer and use it in GitHub Desktop.
Show AWS s3 download_file Progress using tqdm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def hook(t): | |
def inner(bytes_amount): | |
t.update(bytes_amount) | |
return inner | |
BUCKET_NAME = 'your_s3_bucket_name' | |
FILE_NAME = 'your_s3_file_name' | |
s3 = boto3.resource('s3') | |
path = "/tmp/{}".format(FILE_NAME) | |
file_object = s3.Object(BUCKET_NAME, FILE_NAME) | |
filesize = file_object.content_length | |
with tqdm(total=filesize, unit='B', unit_scale=True, desc=FILE_NAME) as t: | |
rootfs.download_file(path, Callback=hook(t)) |
Great!
Easy and simple. Works great for upload_file
as well
This is great, but can you explain to me how it is working?
rootfs.download_file(path, Callback=t.update)
is enough.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you