This library provides an S3 client that supports client-side encryption.
Project description
Amazon S3 Encryption Client for Python
This library provides an S3 client that supports client-side encryption. For more information and detailed instructions for how to use this library, refer to the Amazon S3 Encryption Client Developer Guide.
Getting Started
Requires Python 3.10 or greater. An AWS account is required; standard S3 and KMS charges apply.
The S3 Encryption Client wraps a standard boto3 S3 client and uses a KMS keyring to manage data key encryption. Objects are encrypted before upload and decrypted after download transparently. By default, the client uses AES-GCM with key commitment for content encryption.
import boto3
from s3_encryption import S3EncryptionClient, S3EncryptionClientConfig
from s3_encryption.materials.kms_keyring import KmsKeyring
kms_client = boto3.client("kms", region_name="us-west-2")
keyring = KmsKeyring(kms_client, "arn:aws:kms:us-west-2:123456789012:alias/my-key")
s3_client = boto3.client("s3")
config = S3EncryptionClientConfig(keyring=keyring)
s3ec = S3EncryptionClient(s3_client, config)
# Encrypt and upload
s3ec.put_object(Bucket="my-bucket", Key="my-object", Body=b"secret data")
# Download and decrypt
response = s3ec.get_object(Bucket="my-bucket", Key="my-object")
plaintext = response["Body"].read()
Development
Prerequisites
- Python 3.10 or higher
- uv for package and project management
Setup
Install dependencies:
make install
Testing
Run all tests (unit + integration + examples):
make test
Run unit tests only:
make test-unit
Run integration tests only:
make test-integration
Code Quality
This project uses Ruff for linting and formatting.
Check formatting:
make format-check
Run linter:
make lint
Format code and auto-fix lint issues:
make format
Integration Test Resources
Integration tests require AWS credentials and the following resources. The tests use environment variables to override CI defaults:
| Variable | Description | Default |
|---|---|---|
CI_S3_BUCKET |
S3 bucket for read/write tests | s3ec-python-github-test-bucket |
CI_AWS_REGION |
Primary AWS region | us-west-2 |
CI_KMS_KEY_ALIAS |
KMS key ARN or alias for encryption | arn:aws:kms:us-west-2:370957321024:alias/S3EC-Python-Github-KMS-Key |
CI_MRK_KEY_ID_PRIMARY |
Multi-region key ARN (primary region) | arn:aws:kms:us-west-2:370957321024:key/mrk-cea4cf67c6a046ba829f61f69db5c191 |
CI_MRK_KEY_ID_REPLICA |
Multi-region key ARN (replica region) | arn:aws:kms:us-east-1:370957321024:key/mrk-cea4cf67c6a046ba829f61f69db5c191 |
CI_S3_STATIC_TEST_BUCKET |
Bucket with pre-existing test objects for instruction file tests | s3ec-static-test-objects |
CI_KMS_KEY_STATIC_TESTS |
KMS key used for static test objects | arn:aws:kms:us-west-2:370957321024:key/a3889cd9-99eb-4138-a93a-aea9d52ec2ef |
To run integration tests locally, configure AWS credentials with access to these resources (or your own equivalents) and set the environment variables accordingly.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file amazon_s3_encryption_client_python-4.0.0.tar.gz.
File metadata
- Download URL: amazon_s3_encryption_client_python-4.0.0.tar.gz
- Upload date:
- Size: 448.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ef6b28a267d8de89fc09798a65433144fa67e33e26ce4fb50199b580eeb4c4d
|
|
| MD5 |
731508c08b6b8015e3ecd2e7b7c8faf1
|
|
| BLAKE2b-256 |
640302be44a3ef25363bafa20ad18c5dfb323fdf050bb6663b15305ad46ebb63
|
Provenance
The following attestation bundles were made for amazon_s3_encryption_client_python-4.0.0.tar.gz:
Publisher:
release.yml on aws/amazon-s3-encryption-client-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
amazon_s3_encryption_client_python-4.0.0.tar.gz -
Subject digest:
8ef6b28a267d8de89fc09798a65433144fa67e33e26ce4fb50199b580eeb4c4d - Sigstore transparency entry: 1634422218
- Sigstore integration time:
-
Permalink:
aws/amazon-s3-encryption-client-python@b56eb74e75f2c38f12387e24ac6373215662cb12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aws
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b56eb74e75f2c38f12387e24ac6373215662cb12 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file amazon_s3_encryption_client_python-4.0.0-py3-none-any.whl.
File metadata
- Download URL: amazon_s3_encryption_client_python-4.0.0-py3-none-any.whl
- Upload date:
- Size: 46.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5559b049a055d27d20c57bbac2c2fa306deb3b218cb7d3caaa93eac11bfb4810
|
|
| MD5 |
5083798aa531ec1da8a035a2c7d48fe4
|
|
| BLAKE2b-256 |
61ace8e5371bd7258d2c8092a515a33417ad0a22282459a15c0c715777e5ae39
|
Provenance
The following attestation bundles were made for amazon_s3_encryption_client_python-4.0.0-py3-none-any.whl:
Publisher:
release.yml on aws/amazon-s3-encryption-client-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
amazon_s3_encryption_client_python-4.0.0-py3-none-any.whl -
Subject digest:
5559b049a055d27d20c57bbac2c2fa306deb3b218cb7d3caaa93eac11bfb4810 - Sigstore transparency entry: 1634422257
- Sigstore integration time:
-
Permalink:
aws/amazon-s3-encryption-client-python@b56eb74e75f2c38f12387e24ac6373215662cb12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aws
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b56eb74e75f2c38f12387e24ac6373215662cb12 -
Trigger Event:
workflow_dispatch
-
Statement type: