Created
August 13, 2022 09:17
-
-
Save sebastianschramm/5dc0263eb4b447a41192bd20ee1b79e3 to your computer and use it in GitHub Desktop.
Show tqdm progress bar while uploading file to S3 with boto3
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
from pathlib import Path | |
import boto3 | |
from tqdm import tqdm | |
def upload_to_s3( | |
file_name: str, | |
target_bucket_name: str, | |
target_object_name: str, | |
aws_region: str = "eu-central-1", | |
): | |
s3_client = boto3.client("s3", region_name=aws_region) | |
file_size = Path(file_name).stat().st_size | |
with tqdm(total=file_size, desc=file_name, unit="B", unit_scale=True) as pbar: | |
s3_client.upload_file( | |
file_name, target_bucket_name, target_object_name, Callback=pbar.update | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dependencies: python3.9, boto3 ==1.24.51, tqdm==4.64.0