s3z
Python

Reference

S3Client

The main client. All S3 operations go through this class.

from s3z import Config, S3Client, CredentialSource

config = Config("us-east-1", CredentialSource.Env)
client = S3Client(config)

Methods

MethodReturnsDescription
client.upload(...)list[FileUploadResult]Upload files and directories to S3.
client.download(...)list[FileDownloadResult]Download objects to a local directory.
client.list(...)list[ObjectInfo]List all objects under a prefix.

upload

Upload local files and directories to S3. Directories are walked recursively. Files are split into parts and uploaded in parallel.

results = client.upload(
    ["./data", "./report.csv"],
    "my-bucket",
    "uploads/",
    workers=16,              # files in parallel (default: 32)
    concurrency_per_file=4,  # parts per file (default: 8)
)

for f in results:
    print(f"{f.source} → s3://{f.key} ({f.parts} parts, {f.size} bytes)")
ParameterTypeDefaultDescription
sourceslist[str]Local paths to upload.
bucketstrTarget S3 bucket.
prefixstrKey prefix in the bucket.
workersint | NoneNoneFiles uploaded in parallel.
concurrency_per_fileint | NoneNoneParts per file concurrency.

download

Download all objects under a prefix to a local directory. The prefix structure is preserved on disk.

results = client.download(
    "my-bucket",
    "uploads/",
    "./out",
)

for f in results:
    print(f"s3://{f.key}{f.dest}")
ParameterTypeDefaultDescription
bucketstrSource S3 bucket.
prefixstrKey prefix.
dest_dirstrLocal destination directory.
workersint | NoneNoneFiles downloaded in parallel.
concurrency_per_fileint | NoneNoneParts per file concurrency.

list

List all objects under a prefix. Handles pagination automatically.

objects = client.list(
    "my-bucket",
    "uploads/",
    delimiter="/",  # optional — group by "directory"
)

for obj in objects:
    print(f"{obj.key} ({obj.size} bytes, modified {obj.last_modified})")
ParameterTypeDefaultDescription
bucketstrS3 bucket.
prefixstrKey prefix.
delimiterstr | NoneNoneDelimiter for directory grouping.

Configuration

Config

Config(region, credential_source=None, endpoint=None)
ParameterTypeDefaultDescription
regionstrAWS region (e.g. "us-east-1").
credential_sourceCredentialSource | StaticCredentials | NoneCredentialSource.EnvHow to obtain AWS credentials.
endpointstr | NoneNoneCustom endpoint for S3-compatible backends.

Properties:

PropertyTypeDescription
endpoint_urlstrThe resolved endpoint URL.
regionstrThe AWS region.

CredentialSource

Enum for credential resolution.

VariantDescription
CredentialSource.EnvRead from AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY env vars.

static_credentials

creds = static_credentials("my-access-key", "my-secret-key")
config = Config("us-east-1", creds, endpoint="http://localhost:9000")

Create a credential source from explicit keys. Use this for S3-compatible backends like MinIO, SeaweedFS, or Garage.

Results

FileUploadResult

Returned per file from upload().

FieldTypeDescription
etagstrETag returned by S3.
keystrS3 object key.
partsintNumber of parts used (1 = single PUT).
sizeintFile size in bytes.
sourcestrLocal source path.

FileDownloadResult

Returned per file from download().

FieldTypeDescription
deststrLocal path the file was written to.
keystrS3 key that was downloaded.
partsintNumber of parts used.
sizeintFile size in bytes.

ObjectInfo

Returned per object from list().

FieldTypeDescription
keystrObject key.
sizeintObject size in bytes.
etagstrETag.
last_modifiedstrLast modified timestamp (ISO 8601).

On this page