S3 storage backend for Django
Project description
django-storages-s3
S3 storage backend for Django.
This project is based on django-storages but focuses exclusively on Amazon S3 and S3-compatible storage services (e.g. RustFS, Cloudflare R2, DigitalOcean Spaces). By removing support for other storage backends, it aims to be a leaner, more focused package for projects that only need S3.
Requirements
- Python >= 3.12
- Django >= 5.2
- boto3 >= 1.42
Installation
pip install django-storages-s3
Usage
To save media files to S3:
STORAGES = {
"default": {
"BACKEND": "storages.s3.S3Storage",
"OPTIONS": {
"bucket_name": "my-media-bucket",
"region_name": "us-east-1",
},
},
}
To put static files on S3 via collectstatic:
STORAGES = {
"staticfiles": {
"BACKEND": "storages.s3.S3StaticStorage",
"OPTIONS": {
"bucket_name": "my-static-bucket",
},
},
}
Settings can be provided per-backend via OPTIONS or globally via Django settings (e.g. AWS_STORAGE_BUCKET_NAME). Per-backend options take precedence.
Storage backends
storages.s3.S3Storage- General file storagestorages.s3.S3StaticStorage- Static files (querystring auth disabled)storages.s3.S3ManifestStaticStorage- Static files with Django'sManifestFilesMixin
Authentication
There are several methods for specifying AWS credentials. S3Storage searches for them in this order:
session_profile/AWS_S3_SESSION_PROFILEaccess_key/AWS_S3_ACCESS_KEY_IDorAWS_ACCESS_KEY_IDsecret_key/AWS_S3_SECRET_ACCESS_KEYorAWS_SECRET_ACCESS_KEYsecurity_token/AWS_SESSION_TOKENorAWS_SECURITY_TOKEN- Environment variables
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY - Boto3's default session (instance profile, config files, etc.)
Settings
All settings can be provided as OPTIONS keys (for per-backend configuration) or as global Django settings.
Bucket and storage
| Option | Django setting | Default | Description |
|---|---|---|---|
bucket_name |
AWS_STORAGE_BUCKET_NAME |
Required | The name of the S3 bucket that will host the files. |
location |
AWS_LOCATION |
"" |
A path prefix that will be prepended to all uploads. |
file_overwrite |
AWS_S3_FILE_OVERWRITE |
True |
Whether files with the same name overwrite each other. Set to False to have extra characters appended. |
object_parameters |
AWS_S3_OBJECT_PARAMETERS |
{} |
Parameters set on all objects. See the Boto3 docs for put_object for options like CacheControl, StorageClass, Tagging, and Metadata. |
default_acl |
AWS_DEFAULT_ACL |
None |
ACL for uploaded files (e.g. public-read, private). If None, files are private per Amazon's default. Ignored if ACL is set in object_parameters. See canned ACLs. |
URLs
| Option | Django setting | Default | Description |
|---|---|---|---|
querystring_auth |
AWS_QUERYSTRING_AUTH |
True |
Whether generated URLs include query parameter authentication. Set to False for public buckets. |
querystring_expire |
AWS_QUERYSTRING_EXPIRE |
3600 |
The number of seconds a generated URL is valid for. |
url_protocol |
AWS_S3_URL_PROTOCOL |
"https:" |
The protocol for constructed URLs. Must end in :. Only effective when custom_domain or public_domain is set. |
custom_domain |
AWS_S3_CUSTOM_DOMAIN |
None |
Custom domain for constructed URLs. Must not end in /. |
public_domain |
AWS_S3_PUBLIC_DOMAIN |
None |
Public domain for generated bucket-path URLs when endpoint_url is only reachable by Django. Must not end in /. If querystring_auth is enabled, presigned URLs are generated against this domain. |
When public_domain is set, url() uses it for external URLs while storage operations continue to use endpoint_url.
Connection
| Option | Django setting | Default | Description |
|---|---|---|---|
endpoint_url |
AWS_S3_ENDPOINT_URL |
None |
Custom S3 URL including scheme. Overrides region_name and use_ssl. Set region_name too to avoid AuthorizationQueryParametersError. |
region_name |
AWS_S3_REGION_NAME |
None |
Name of the AWS S3 region (e.g. eu-west-1). |
use_ssl |
AWS_S3_USE_SSL |
True |
Whether to use SSL when connecting to S3. |
verify |
AWS_S3_VERIFY |
None |
Whether to verify the connection to S3. Can be False or a path to a CA cert bundle. |
addressing_style |
AWS_S3_ADDRESSING_STYLE |
None |
"virtual" or "path". |
signature_version |
AWS_S3_SIGNATURE_VERSION |
None |
Default is s3v4. Set to s3 for legacy v2 signing (only supported in certain regions). |
proxies |
AWS_S3_PROXIES |
None |
Dictionary of proxy servers, e.g. {"http": "foo.bar:3128"}. |
client_config |
AWS_S3_CLIENT_CONFIG |
None |
A botocore.config.Config instance for advanced configuration. Note: overrides addressing_style, signature_version, and proxies. See botocore docs. |
transfer_config |
AWS_S3_TRANSFER_CONFIG |
None |
A boto3.s3.transfer.TransferConfig instance to customize transfer options. See Boto3 docs. |
Compression
| Option | Django setting | Default | Description |
|---|---|---|---|
gzip |
AWS_IS_GZIPPED |
False |
Whether to enable gzip compression for content types specified by gzip_content_types. |
gzip_content_types |
GZIP_CONTENT_TYPES |
text/css, text/javascript, application/javascript, application/x-javascript, image/svg+xml |
Content types to gzip when gzip is True. |
Other
| Option | Django setting | Default | Description |
|---|---|---|---|
max_memory_size |
AWS_S3_MAX_MEMORY_SIZE |
0 |
Maximum bytes a file can take before being rolled over to a temporary file on disk. 0 means no rollover. |
IAM Policy
Minimum IAM policy for common usage:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObjectAcl",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject",
"s3:PutObjectAcl"
],
"Resource": [
"arn:aws:s3:::example-bucket-name/*",
"arn:aws:s3:::example-bucket-name"
]
}
]
}
For more information about Principal, see AWS JSON Policy Elements.
License
BSD 3-Clause. See LICENSE for details.
Project details
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 django_storages_s3-0.1.4.tar.gz.
File metadata
- Download URL: django_storages_s3-0.1.4.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2483cab13fd6c9f04f8074fbeec1c0c6f749c6db7bb649d8ccf16e0ddb5e974
|
|
| MD5 |
9c83fc73ffe836859d8c7cee84d1911a
|
|
| BLAKE2b-256 |
2ef06046451ed214ca765e78f67a693ef04adcb1256e318111990c89a78ee418
|
Provenance
The following attestation bundles were made for django_storages_s3-0.1.4.tar.gz:
Publisher:
publish.yml on vchrisb/django-storages-s3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_storages_s3-0.1.4.tar.gz -
Subject digest:
f2483cab13fd6c9f04f8074fbeec1c0c6f749c6db7bb649d8ccf16e0ddb5e974 - Sigstore transparency entry: 1393627641
- Sigstore integration time:
-
Permalink:
vchrisb/django-storages-s3@72e688512cd245c5bcde4779a1c2d5f5b143388e -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/vchrisb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@72e688512cd245c5bcde4779a1c2d5f5b143388e -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_storages_s3-0.1.4-py3-none-any.whl.
File metadata
- Download URL: django_storages_s3-0.1.4-py3-none-any.whl
- Upload date:
- Size: 15.2 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 |
ea430bc24b5277c732d41d5ce12fa7d84f4d834756ad6f3fca214c65bd3b468a
|
|
| MD5 |
615a87951baeb5f0b1f32e33af706f6d
|
|
| BLAKE2b-256 |
586dd2e8d16504d0655229e014252ae80922ae0ea457ae45ed9388c49943357c
|
Provenance
The following attestation bundles were made for django_storages_s3-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on vchrisb/django-storages-s3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_storages_s3-0.1.4-py3-none-any.whl -
Subject digest:
ea430bc24b5277c732d41d5ce12fa7d84f4d834756ad6f3fca214c65bd3b468a - Sigstore transparency entry: 1393627647
- Sigstore integration time:
-
Permalink:
vchrisb/django-storages-s3@72e688512cd245c5bcde4779a1c2d5f5b143388e -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/vchrisb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@72e688512cd245c5bcde4779a1c2d5f5b143388e -
Trigger Event:
push
-
Statement type: