Support for many storage backends in Django
Project description
Installation
Installing from PyPI is as easy as doing:
pip install django-storages
If you’d prefer to install from source (maybe there is a bugfix in master that hasn’t been released yet) then the magic incantation you are looking for is:
pip install -e 'git+https://github.com/jschneier/django-storages.git#egg=django-storages'
Once that is done set DEFAULT_FILE_STORAGE to the backend of your choice. If, for example, you want to use the boto3 backend you would set:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
If you are using the FileSystemStorage as your storage management class in your models FileField fields, remove them and don’t specify any storage parameter. That way, the DEFAULT_FILE_STORAGE class will be used by default in your field. For example, if you have a photo field defined as:
photo = models.FileField(
storage=FileSystemStorage(location=settings.MEDIA_ROOT),
upload_to='photos',
)
Set it to just:
photo = models.FileField(
upload_to='photos',
)
There are also a number of settings available to control how each storage backend functions, please consult the documentation for a comprehensive list.
About
django-storages is a project to provide a variety of storage backends in a single library.
This library is usually compatible with the currently supported versions of Django. Check the Trove classifiers in setup.py to be sure.
History
This repo began as a fork of the original library under the package name of django-storages-redux and became the official successor (releasing under django-storages on PyPI) in February of 2016.
Found a Bug? Something Unsupported?
I suspect that a few of the storage engines in backends/ have been unsupported for quite a long time. I personally only really need the S3Storage backend but welcome bug reports (and especially) patches and tests for some of the other backends.
Issues are tracked via GitHub issues at the project issue page.
Documentation
Documentation for django-storages is located at https://django-storages.readthedocs.io/.
Contributing
Check for open issues at the project issue page or open a new issue to start a discussion about a feature or bug.
Fork the django-storages repository on GitHub to start making changes.
Add a test case to show that the bug is fixed or the feature is implemented correctly.
Bug me until I can merge your pull request. Also, don’t forget to add yourself to AUTHORS.
django-storages CHANGELOG
1.7.2 (2019-09-10)
S3
Avoid misleading AWS_DEFAULT_ACL warning for insecure default_acl when overridden as a class variable (#591_)
Propagate file deletion to cache when preload_metadata is True, (not the default) (#743, #749)
Fix exception raised on closed file (common if using ManifestFilesMixin or collectstatic. (#382, #754)
Azure
Pare down the required packages in extra_requires when installing the azure extra to only azure-storage-blob (#680, #684)
Fix compatability with generate_blob_shared_access_signature updated signature (#705, #723)
Fetching a file now uses the configured timeout rather than hardcoding one (#727)
Add support for configuring all blobservice options: AZURE_EMULATED_MODE, AZURE_ENDPOINT_SUFFIX, AZURE_CUSTOM_DOMAIN, AZURE_CONNECTION_STRING, AZURE_CUSTOM_CONNECTION_STRING, AZURE_TOKEN_CREDENTIAL. See the docs for more info. Huge thanks once again to @nitely. (#750)
Fix filename handling to not strip special characters (#609, #752)
Google Cloud
Set the file acl in the same call that uploads it (#698)
Reduce the number of queries and required permissions when GS_AUTO_CREATE_BUCKET is False (the default) (#412, #718)
Set the predefined_acl when creating a GoogleCloudFile using .write (#640, #756)
Add GS_BLOB_CHUNK_SIZE setting to enable efficient uploading of large files (#757)
Dropbox
SFTP
Fix reopening a file (#746)
1.7.1 (2018-09-06)
Fix off-by-1 error in get_available_name whenever file_overwrite or overwrite_files is True (#588, #589)
Change S3Boto3Storage.listdir() to use list_objects instead of list_objects_v2 to restore compatability with services implementing the S3 protocol that do not yet support the new method (#586, #590)
1.7 (2018-09-03)
Security
The S3BotoStorage and S3Boto3Storage backends have an insecure default ACL of public-read. It is recommended that all current users audit their bucket permissions. Support has been added for setting AWS_DEFAULT_ACL = None and AWS_BUCKET_ACL = None which causes all created files to inherit the bucket’s ACL (and created buckets to inherit the Amazon account’s default ACL). This will become the default in version 2.0 (for S3Boto3Storage only since S3BotoStorage will be removed in version 1.8, see below). Additionally, a warning is now raised if AWS_DEFAULT_ACL or AWS_BUCKET_ACL is not explicitly set. (#381, #535, #579)
Breaking
The AzureStorage backend and documentation has been completely rewritten. It now depends on azure and azure-storage-blob and is vastly improved. Big thanks to @nitely and all other contributors along the way (#565)
The .url() method of GoogleCloudStorage has been completely reworked. Many use cases should require no changes and will experience a massive speedup. The .url() method no longer hits the network for public urls and generates signed urls (with a default of 1-day expiration, configurable via GS_EXPIRATION) for non-public buckets. Check out the docs for more information. (#570)
Various backends will now raise ImproperlyConfigured at runtime if their location (GS_LOCATION, AWS_LOCATION) begins with a leading / rather than silently stripping it. Verify yours does not. (#520)
The long deprecated GSBotoStorage backend is removed. (#518)
Deprecation
The insecure default of public-read for AWS_DEFAULT_ACL and AWS_BUCKET_ACL in S3Boto3Storage will change to inherit the bucket’s setting in version 2.0 (#579)
The legacy S3BotoBackend is deprecated and will be removed in version 1.8. It is strongly recommended to move to the S3Boto3Storage backend for performance, stability and bugfix reasons. See the boto migration docs for step-by-step guidelines. (#578, #584)
The long aliased arguments to S3Boto3Storage of acl and bucket are deprecated in favor of bucket_name and default_acl (#516)
The minimum required version of boto3 will be increasing to 1.4.4 in the next major version of django-storages. (#583)
Features
Add support for a file to inherit its bucket’s ACL by setting AWS_DEFAULT_ACL = None (#535)
Add GS_CACHE_CONTROL setting for GoogleCloudStorage backend (#411, #505)
Add documentation around using django-storages with Digital Ocean Spaces (#521)
Add support for Django 2.1 and Python 3.7 (#530)
Make S3Boto3Storage pickleable (#551)
Unconditionally set the security token in the boto backends (b13efd)
Improve efficiency of .listdir on S3Boto3Storage (#352)
Add AWS_S3_VERIFY to support custom certificates and disabling certificate verification to S3Boto3Storage (#486, #580)
Add AWS_S3_PROXIES setting to S3Boto3Storage (#583)
Add a snazzy new logo. Big thanks to @reallinfo
Bugfixes
Reset file read offset before passing to GoogleCloudStorage and AzureStorage (#481, #581, #582)
Fix various issues with multipart uploads in the S3 backends (#169, #160, #364, #449, #504, #506, #546)
Fix S3Boto3Storage to stream down large files (also disallow r+w mode) (#383, #548)
Fix SFTPStorageFile to align with the core File abstraction (#487, #568)
Catch IOError in SFTPStorage.delete (#568)
AzureStorage, GoogleCloudStorage, S3Boto3Storage and S3BotoStorage now respect max_length when file_overwrite = True (#513, #554)
The S3 backends now consistently use compresslevel=9 (the Python stdlib default) for gzipped content (#572, #576)
Improve error message of S3Boto3Storage during an unexpected exception when automatically creating a bucket (#574, #577)
1.6.6 (2018-03-26)
You can now specify the backend you are using to install the necessary dependencies using extra_requires. For example pip install django-storages[boto3] (#417)
Add additional content-type detection fallbacks (#406, #407)
Add GS_LOCATION setting to specify subdirectory for GoogleCloudStorage (#355)
Add support for uploading large files to DropBoxStorage, fix saving files (#379, #378, #301)
Drop support for Django 1.8 and Django 1.10 (and hence Python 3.3) (#438)
Implement get_created_time for GoogleCloudStorage (#464)
1.6.5 (2017-08-01)
1.6.4 (2017-07-27)
Files uploaded with GoogleCloudStorage will now set their appropriate mimetype (#320)
Fix DropBoxStorage.url to work. (#357)
Fix S3Boto3Storage when AWS_PRELOAD_METADATA = True (#366)
Fix S3Boto3Storage uploading file-like objects without names (#195, #368)
S3Boto3Storage is now threadsafe - a separate session is created on a per-thread basis (#268, #358)
1.6.3 (2017-06-23)
Revert default AWS_S3_SIGNATURE_VERSION to V2 to restore backwards compatability in S3Boto3. It’s recommended that all new projects set this to be 's3v4'. (#344)
1.6.2 (2017-06-22)
1.6.1 (2017-06-22)
1.6 (2017-06-21)
Breaking: Remove backends deprecated in v1.5.1 (#280)
Breaking: DropBoxStorage has been upgrade to support v2 of the API, v1 will be shut off at the end of the month - upgrading is recommended (#273)
Breaking: The SFTPStorage backend now checks for the existence of the fallback ~/.ssh/known_hosts before attempting to load it. If you had previously been passing in a path to a non-existent file it will no longer attempt to load the fallback. (#118, #325)
Breaking: The default version value for AWS_S3_SIGNATURE_VERSION is now 's3v4'. No changes should be required (#335)
Deprecation: The undocumented gs.GSBotoStorage backend. See the new gcloud.GoogleCloudStorage or apache_libcloud.LibCloudStorage backends instead. (#236)
Add a new backend, gcloud.GoogleCloudStorage based on the google-cloud bindings. (#236)
Pass in the location constraint when auto creating a bucket in S3Boto3Storage (#257, #258)
Add support for reading AWS_SESSION_TOKEN and AWS_SECURITY_TOKEN from the environment to S3Boto3Storage and S3BotoStorage. (#283)
Fix collectstatic timezone handling in and add get_modified_time to S3BotoStorage (#290)
Add support for Django 1.11 (#295)
Add project keyword support to GCS in LibCloudStorage backend (#269)
Files that have a guessable encoding (e.g. gzip or compress) will be uploaded with that Content-Encoding in the s3boto3 backend (#263, #264)
The Dropbox backend now properly translates backslashes in Windows paths into forward slashes (e52a127)
1.5.2 (2017-01-13)
Actually use SFTP_STORAGE_HOST in SFTPStorage backend (#204)
Fix S3Boto3Storage to avoid race conditions in a multi-threaded WSGI environment (#238)
Fix trying to localize a naive datetime when settings.USE_TZ is False in S3Boto3Storage.modified_time. (#235, #234)
Fix automatic bucket creation in S3Boto3Storage when AWS_AUTO_CREATE_BUCKET is True (#196)
Improve the documentation for the S3 backends
1.5.1 (2016-09-13)
Breaking: Drop support for Django 1.7 (#185)
Deprecation: hashpath, image, overwrite, mogile, symlinkorcopy, database, mogile, couchdb. See (#202) to discuss maintenance going forward
Use a fixed mtime argument for GzipFile in S3BotoStorage and S3Boto3Storage to ensure a stable output for gzipped files
Use .putfileobj instead of .put in S3Boto3Storage to use the transfer manager, allowing files greater than 5GB to be put on S3 (#194 , #201)
Update S3Boto3Storage for Django 1.10 (#181) (get_modified_time and get_accessed_time)
Fix bad kwarg name in S3Boto3Storage when AWS_PRELOAD_METADATA is True (#189, #190)
1.5.0 (2016-08-02)
Add new backend S3Boto3Storage (#179)
Add a strict option to utils.setting (#176)
Tests, documentation, fixing .close for SFTPStorage (#177)
Tests, documentation, add .readlines for FTPStorage (#175)
Tests and documentation for DropBoxStorage (#174)
Fix MANIFEST.in to not ship .pyc files. (#145)
Enable CI testing of Python 3.5 and fix test failure from api change (#171)
1.4.1 (2016-04-07)
Files that have a guessable encoding (e.g. gzip or compress) will be uploaded with that Content-Encoding in the s3boto backend. Compressable types such as application/javascript will still be gzipped. PR #122
Fix DropBoxStorage.exists check and add DropBoxStorage.url (#127)
Add GS_HOST setting (with a default of GSConnection.DefaultHost) to fix GSBotoStorage. (#124, #125)
1.4 (2016-02-07)
This package is now released on PyPI as django-storages. Please update your requirements files to django-storages==1.4.
1.3.2 (2016-01-26)
Fix memory leak from not closing underlying temp file in s3boto backend (#106)
Allow easily specifying a custom expiry time when generating a url for S3BotoStorage (#96)
Check for bucket existence when the empty path (‘’) is passed to storage.exists in S3BotoStorage - this prevents a crash when running collectstatic -c on Django 1.9.1 (#112) fixed in #116
1.3.1 (2016-01-12)
A few Azure Storage fixes [pass the content-type to Azure, handle chunked content, fix url] (#45)
Add support for a Dropbox (dropbox) storage backend
Various fixes to the apache_libcloud backend [return the number of bytes asked for by .read, make .name non-private, don’t initialize to an empty BytesIO object] (#55)
Fix multi-part uploads in s3boto backend not respecting AWS_S3_ENCRYPTION (#94)
Automatically gzip svg files (#100)
1.3 (2015-08-14)
Breaking: Drop Support for Django 1.5 and Python 2.6
Breaking: Remove previously deprecated mongodb backend
Breaking: Remove previously deprecated parse_ts_extended from s3boto storage
Add support for Django 1.8+ (#36)
Add AWS_S3_PROXY_HOST and AWS_S3_PROXY_PORT settings for s3boto backend (#41)
Fix Python3K compat issue in apache_libcloud (#52)
Fix Google Storage backend not respecting GS_IS_GZIPPED setting (#51, #60)
Rename FTP _name attribute to name which is what the Django File api is expecting (#70)
Put StorageMixin first in inheritance to maintain backwards compat with older versions of Django (#63)
1.2.3 (2015-03-14)
Variety of FTP backend fixes (fix exists, add modified_time, remove call to non-existent function) (#26)
Apparently the year changed to 2015
1.2.2 (2015-01-28)
1.2.1 (2014-12-31)
1.2 (2014-12-14)
Breaking: Remove legacy S3 storage (#1)
Breaking: Remove mosso files backend (#2)
Add text/javascript mimetype to S3BotoStorage gzip allowed defaults
Add support for Django 1.7 migrations in S3BotoStorage and ApacheLibCloudStorage (#5, #8)
Python3K (3.3+) now available for S3Boto backend (#4)
NOTE: Version 1.1.9 is the first release of django-storages after the fork. It represents the current (2014-12-08) state of the original django-storages in master with no additional changes. This is the first release of the code base since March 2013.
1.1.9 (2014-12-08)
Fix syntax for Python3 with pull-request #91
Support pushing content type from File object to GridFS with pull-request #90
Support passing a region to the libcloud driver with pull-request #86
Handle trailing slash paths fixes #188 fixed by pull-request #85
Use a SpooledTemporaryFile to conserve memory in S3BotoFile pull-request #69
Guess content-type for S3BotoStorageFile the same way that _save() in S3BotoStorage does
Pass headers and response_headers through from url to generate_url in S3BotoStorage pull-request #65
Added AWS_S3_HOST, AWS_S3_PORT and AWS_S3_USE_SSL settings to specify host, port and is_secure in pull-request #66
Everything Below Here Was Previously Released on PyPI under django-storages
1.1.8 (2013-03-31)
Fixes #156 regarding date parsing, ValueError when running collectstatic
Proper handling of boto dev version parsing
Made SFTP URLs accessible, now uses settings.MEDIA_URL instead of sftp://
1.1.7 (2013-03-20)
Listing of huge buckets on S3 is now prevented by using the prefix argument to boto’s list() method
Initial support for Windows Azure Storage
Switched to useing boto’s parse_ts date parser getting last modified info when using S3boto backend
Fixed key handling in S3boto and Google Storage backends
Account for lack of multipart upload in Google Storage backend
Fixed seek() issue when using AWS_IS_GZIPPED by darkness51 with pull-request #50
Improvements to S3BotoStorage and GSBotoStorage
1.1.6 (2013-01-06)
Merged many changes from Jannis Leidel (mostly regarding gzipping)
Fixed tests by Ian Lewis
Added support for Google Cloud Storage backend by Jannis Leidel
Updated license file by Dan Loewenherz, fixes #133 with pull-request #44
Set Content-Type header for use in upload_part_from_file by Gerardo Curiel
Pass the rewind parameter to Boto’s set_contents_from_file method by Jannis Leidel with pull-request #45
Fix for FTPStorageFile close() method by Mathieu Comandon with pull-request #43
Minor refactoring by Oktay Sancak with pull-request #48
Ungzip on download based on Content-Encoding by Gavin Wahl with pull-request #46
Add support for S3 server-side encryption by Tobias McNulty with pull-request #17
Add an optional setting to the boto storage to produce protocol-relative URLs, fixes #105
1.1.5 (2012-07-18)
Merged pull request #36 from freakboy3742 Keith-Magee, improvements to Apache Libcloud backend and docs
Merged pull request #35 from atodorov, allows more granular S3 access settings
Add support for SSL in Rackspace Cloudfiles backend
Fixed the listdir() method in s3boto backend, fixes #57
Added base url tests for safe_join in s3boto backend
Merged pull request #20 from alanjds, fixed SuspiciousOperation warning if AWS_LOCATION ends with ‘/’
Added FILE_BUFFER_SIZE setting to s3boto backend
Merged pull request #30 from pendletongp, resolves #108, #109 and #110
Updated the modified_time() method so that it doesn’t require dateutil. fixes #111
Merged pull request #16 from chamal, adds Apache Libcloud backend
When preloading the S3 metadata make sure we reset the files key during saving to prevent stale metadata
Merged pull request #24 from tobias.mcnulty, fixes bug where s3boto backend returns modified_time in wrong time zone
Fixed HashPathStorage.location to no longer use settings.MEDIA_ROOT
Remove download_url from setup file so PyPI dist is used
1.1.4 (2012-01-06)
Added PendingDeprecationWarning for mosso backend
Merged pull request #13 from marcoala, adds SFTP_KNOWN_HOST_FILE setting to SFTP storage backend
Merged pull request #12 from ryankask, fixes HashPathStorage tests that delete remote media
Merged pull request #10 from key, adds support for django-mongodb-engine 0.4.0 or later, fixes GridFS file deletion bug
Fixed S3BotoStorage performance problem calling modified_time()
Added deprecation warning for s3 backend, refs #40
Fixed CLOUDFILES_CONNECTION_KWARGS import error, fixes #78
Switched to sphinx documentation, set official docs up on https://django-storages.readthedocs.io/
HashPathStorage uses self.exists now, fixes #83
1.1.3 (2011-08-15)
Created this lovely change log
Fixed #89: broken StringIO import in CloudFiles backend
Merged pull request #5: HashPathStorage path bug
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
File details
Details for the file django-storages-1.7.2.tar.gz
.
File metadata
- Download URL: django-storages-1.7.2.tar.gz
- Upload date:
- Size: 89.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b3def96493d3ccde37b864cea376472baf6e8a596504b209278801c510b807 |
|
MD5 | 5a52bdfc7330da2c028e1883640285b7 |
|
BLAKE2b-256 | aae4c69836e7197222b229c6f49bb0cc2574b661bd5f71a6a46064b768c25946 |
File details
Details for the file django_storages-1.7.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_storages-1.7.2-py2.py3-none-any.whl
- Upload date:
- Size: 45.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87287b7ad2e789cd603373439994e1ac6f94d9dc2e5f8173d2a87aa3ed458bd9 |
|
MD5 | 3ae3c40ea20383ca3a9f92fab5d07519 |
|
BLAKE2b-256 | bbe3f63efefa33c62fbb700b9a5af40791b4d7c75d50b4cd604065c894e780fd |