Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save konanast/7543608b78aaf32ba6f65b8c97d3f280 to your computer and use it in GitHub Desktop.
Save konanast/7543608b78aaf32ba6f65b8c97d3f280 to your computer and use it in GitHub Desktop.
Show AWS s3 download_file Progress using tqdm
#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