Forked from LouisAmon/s3_download_file_progress_bar.py
Last active
April 20, 2019 16:38
-
-
Save konanast/7543608b78aaf32ba6f65b8c97d3f280 to your computer and use it in GitHub Desktop.
Show AWS s3 download_file Progress using tqdm
This file contains hidden or 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 | |
import boto3 | |
from tqdm import tqdm | |
import io | |
BUCKET_NAME = '' | |
access_key = '' | |
secret_key = '' | |
host = '' | |
S3_FILE_NAME = '' | |
localfile = io.BytesIO() | |
session = boto3.session.Session( | |
aws_access_key_id=secret_key, aws_secret_access_key=access_key) | |
s3 = session.resource('s3', endpoint_url=host) | |
bucket = s3.Bucket(BUCKET_NAME) | |
object = bucket.Object(S3_FILE_NAME) | |
filesize = object.content_length | |
print(S3_FILE_NAME) | |
print(filesize) | |
def hook(t): | |
def inner(bytes_amount): | |
t.update(bytes_amount) | |
return inner | |
with tqdm(total=filesize, unit='B', unit_scale=True, desc="FILE") as t: | |
object.download_fileobj(localfile, Callback=hook(t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment