Forked from wy193777/s3_download_file_progress_bar.py
Last active
March 2, 2024 16:45
-
-
Save LTeder/8e6f3aab692f0b92150ae26c8e33d5de to your computer and use it in GitHub Desktop.
AWS S3 download_fileobj tqdm progress callback
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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This modification comes from here