Skip to content

Instantly share code, notes, and snippets.

@wy193777
Last active July 20, 2023 15:52
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wy193777/e7607d12fad13459e8992d4f69b53586 to your computer and use it in GitHub Desktop.
Save wy193777/e7607d12fad13459e8992d4f69b53586 to your computer and use it in GitHub Desktop.
Show AWS s3 download_file Progress using tqdm
#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))
@NescobarAlopLop
Copy link

Thank you

@orena1
Copy link

orena1 commented Apr 1, 2021

Great!

@samuelduchesne
Copy link

Easy and simple. Works great for upload_file as well

@jtele2
Copy link

jtele2 commented Mar 26, 2023

This is great, but can you explain to me how it is working?

@Walz
Copy link

Walz commented Jul 20, 2023

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