Skip to main content

django-s3-storage

django-s3-storage provides a Django Amazon S3 file storage.

Features

  • Django file storage for Amazon S3.

  • Django static file storage for Amazon S3.

  • Works in Python 3!

Installation

  1. Install using pip install django-s3-storage.

  2. Add 'django_s3_storage' to your INSTALLED_APPS setting.

  3. Set your DEFAULT_FILE_STORAGE setting to "django_s3_storage.storage.S3Storage".

  4. Set your STATICFILES_STORAGE setting to "django_s3_storage.storage.StaticS3Storage" or "django_s3_storage.storage.ManifestStaticS3Storage".

  5. Configure your Amazon S3 settings (see Available settings, below).

Available settings

# The region to connect to when storing files.
AWS_REGION = "us-east-1"

# The AWS access key used to access the storage buckets.
AWS_ACCESS_KEY_ID = ""

# The AWS secret access key used to access the storage buckets.
AWS_SECRET_ACCESS_KEY = ""

# The S3 bucket used to store uploaded files.
AWS_S3_BUCKET_NAME = ""

# The S3 calling format to use to connect to the bucket.
AWS_S3_CALLING_FORMAT = "boto.s3.connection.OrdinaryCallingFormat"

# A prefix to add to the start of all uploaded files.
AWS_S3_KEY_PREFIX = ""

# Whether to enable querystring authentication for uploaded files.
AWS_S3_BUCKET_AUTH = True

# The expire time used to access uploaded files.
AWS_S3_MAX_AGE_SECONDS = 60*60  # 1 hour.

# A custom URL prefix to use for public-facing URLs for uploaded files.
AWS_S3_PUBLIC_URL = ""

# Whether to set the storage class of uploaded files to REDUCED_REDUNDANCY.
AWS_S3_REDUCED_REDUNDANCY = False

# The S3 bucket used to store static files.
AWS_S3_BUCKET_NAME_STATIC = ""

# The S3 calling format to use to connect to the static bucket.
AWS_S3_CALLING_FORMAT_STATIC = "boto.s3.connection.OrdinaryCallingFormat"

# Whether to enable querystring authentication for static files.
AWS_S3_BUCKET_AUTH_STATIC = False

# A prefix to add to the start of all static files.
AWS_S3_KEY_PREFIX_STATIC = ""

# The expire time used to access static files.
AWS_S3_MAX_AGE_SECONDS_STATIC = 60*60*24*365  # 1 year.

# A custom URL prefix to use for public-facing URLs for static files.
AWS_S3_PUBLIC_URL_STATIC = ""

# Whether to set the storage class of static files to REDUCED_REDUNDANCY.
AWS_S3_REDUCED_REDUNDANCY_STATIC = False

Important: If you change any of the AWS_S3_BUCKET_AUTH or AWS_S3_MAX_AGE_SECONDS settings, you will need to run ./manage.py s3_sync_meta path.to.your.storage before the changes will be applied to existing media files.

How it works

By default, uploaded user files are stored on Amazon S3 using the private access control level. When a URL for the file is generated, querystring auth with a timeout of 1 hour is used to secure access to the file.

By default, static files are stored on Amazon S3 using the public access control level and aggressive caching.

Text-based files, such as HTML, XML and JSON, are stored using gzip to save space and improve download performance.

At the moment, files stored on S3 can only be opened in read-only mode.

Optimizing media file caching

The default settings assume that user-uploaded file are private. This means that they are only accessible via S3 authenticated URLs, which is bad for browser caching.

To make user-uploaded files public, and enable aggressive caching, make the following changes to your settings.py.

AWS_S3_BUCKET_AUTH = False

AWS_S3_MAX_AGE_SECONDS = 60*60*24*365  # 1 year.

Important: By making these changes, all user-uploaded files will be public. Ensure they do not contain confidential information.

Important: If you change any of the AWS_S3_BUCKET_AUTH or AWS_S3_MAX_AGE_SECONDS settings, you will need to run ./manage.py s3_sync_meta path.to.your.storage before the changes will be applied to existing media files.

Management commands

s3_sync_meta

Syncronizes the meta information on S3 files.

If you change any of the AWS_S3_BUCKET_AUTH or AWS_S3_MAX_AGE_SECONDS settings, you will need to run this command before the changes will be applied to existing media files.

Example usage: ./manage.py s3_sync_meta django.core.files.storage.default_storage

How does django-s3-storage compare with django-storages?

The django-storages-redux fork of django-storages appears to be the most widely used S3 storage backend for Django. It also supports a variety of other storage backends.

django-s3-storage provides similar features, but only supports S3. It was originally written to support Python 3 at a time when the future of django-storages was unclear. It’s a small, well-tested and self-contained library that aims to do one thing very well.

The author of django-s3-storage is not aware of significant differences in functionality with django-storages-redux. If you notice some differences, please file an issue!

Build status

This project is built on every push using the Travis-CI service.

https://travis-ci.org/etianen/django-s3-storage.svg?branch=master

Support and announcements

Downloads and bug tracking can be found at the main project website.

More information

The django-s3-storage project was developed by Dave Hall. You can get the code from the django-s3-storage project site.

Dave Hall is a freelance web developer, based in Cambridge, UK. You can usually find him on the Internet in a number of different places:

Metadata

Release files for django-s3-storage-patched 0.9.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-s3-storage-patched 0.9.6.2
File Size Uploaded Provenance
django-s3-storage-patched-0.9.6.2.tar.gz 11.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-s3-storage-patched 0.9.6.2
File Interpreter ABI Platform
django_s3_storage_patched-0.9.6.2-py3.4.egg Legacy Egg format - - Details

Total release size: 59.3 kB

Release files / django-s3-storage-patched-0.9.6.2.tar.gz

Download URL django-s3-storage-patched-0.9.6.2.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c148549f53300c88d60c54a4bec81248b1d05254a993aa9f5382de62bc826e84
BLAKE2b-256 checksum
How to use checksums
1e111f0ef01d0ed1f1ccac9c87ce59294c7498f3cbfa92e1dee6c9eea82c7555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_s3_storage_patched-0.9.6.2-py3.4.egg

Download URL django_s3_storage_patched-0.9.6.2-py3.4.egg
Size 48.1 kB
Tags Egg
SHA-256 checksum
How to use checksums
489f83503d7b9d412055a4b7020441a756a3420587f13dafced5b94e8b8a17ff
BLAKE2b-256 checksum
How to use checksums
470e8b0b9c66e98decb34437a25b1decda2e664648574766bbaa96682a2e5ab8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-s3-storage-patched 0.9.6.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.6.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page