s3transfer

0.16.0 · active · verified Sat Mar 28

s3transfer is an Amazon S3 Transfer Manager for Python, maintained by Amazon Web Services. It provides managed multipart uploads and downloads, automatic retries, progress callbacks, bandwidth throttling, and optional AWS CRT-accelerated transfers. As of version 0.16.0 it defaults to CRC32 checksums and supports user-provided full-object checksums. The project is NOT yet generally available (GA); minor-version bumps may contain breaking interface changes, so production deployments must pin to a minor version. It is bundled as a dependency of boto3 and botocore and is typically consumed indirectly through those SDKs.

Warnings

Install

Imports

Quickstart

Upload and download a file using TransferManager via the stable boto3.s3.transfer interface, with a custom TransferConfig.

import os
import boto3
from boto3.s3.transfer import TransferConfig, S3Transfer

# Credentials resolved from env, ~/.aws/credentials, or IAM role
aws_access_key = os.environ.get('AWS_ACCESS_KEY_ID', '')
aws_secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY', '')
region = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
bucket = os.environ.get('S3_BUCKET', 'my-bucket')

client = boto3.client(
    's3',
    region_name=region,
    aws_access_key_id=aws_access_key or None,
    aws_secret_access_key=aws_secret_key or None,
)

config = TransferConfig(
    multipart_threshold=8 * 1024 * 1024,   # 8 MB
    max_concurrency=10,
    num_download_attempts=5,
    use_threads=True,
    # Force classic manager; use 'auto' to allow CRT when awscrt is installed
    preferred_transfer_client='classic',
)

transfer = S3Transfer(client, config)

# Upload
transfer.upload_file(
    '/tmp/example.txt',
    bucket,
    'uploads/example.txt',
    extra_args={'ContentType': 'text/plain'},
)

# Download
transfer.download_file(
    bucket,
    'uploads/example.txt',
    '/tmp/example_downloaded.txt',
)

print('Transfer complete')

view raw JSON →