Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save LTeder/8e6f3aab692f0b92150ae26c8e33d5de to your computer and use it in GitHub Desktop.

Select an option

Save LTeder/8e6f3aab692f0b92150ae26c8e33d5de to your computer and use it in GitHub Desktop.
AWS S3 download_fileobj tqdm progress callback
#python3
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, desc=f'source: s3://{s3_bucket}/{s3_object_key}',
bar_format="{percentage:.1f}%|{bar:25} | {rate_fmt} | {desc}",
unit='B', unit_scale=True, unit_divisor=1024) as pbar:
with open(path, 'wb') as f:
s3_client.download_fileobj(s3_bucket, s3_object_key, f, Callback=pbar.update)
@LTeder

LTeder commented Jul 29, 2022

Copy link
Copy Markdown
Author

This modification comes from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment