Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sebastianschramm/5dc0263eb4b447a41192bd20ee1b79e3 to your computer and use it in GitHub Desktop.
Save sebastianschramm/5dc0263eb4b447a41192bd20ee1b79e3 to your computer and use it in GitHub Desktop.
Show tqdm progress bar while uploading file to S3 with boto3
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
)
@sebastianschramm
Copy link
Author

dependencies: python3.9, boto3 ==1.24.51, tqdm==4.64.0

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