Multiple Storage Engines
Project description
=======================
django-fallback-storage
=======================
.. image:: https://badge.fury.io/py/django-fallback-storage.png
:target: https://badge.fury.io/py/django-fallback-storage
.. image:: https://travis-ci.org/pipermerriam/django-fallback-storage.png?branch=master
:target: https://travis-ci.org/pipermerriam/django-fallback-storage
``django-fallback-storage`` allows for the use of multiple storage engines at
the same time. It works by iterating through the declared storage backends
until one succeeds with the desired storage action.
While usable in a production environment, this tool was primarily designed to
help with development of a project.
Consider a production site using the ``S3BotoStorage`` backend to store its
static assets on Amazon S3 and a development environment that regularly gets
database dumps from the production environment. In order to get the media
associated with the database dump to work, the development environment could be
configured to use the same S3 bucket. This could be problematic, as it would
risk making unwanted modifications to the production media.
The ``FallbackStorage`` backend provided by ``django-fallback-storage`` allows
use of the same production production media source in the development
environment while delegating all write operations to a different storage
backend (such as the filesystem).
This is accomplished by wrapping multiple storage backends, and iterating
through them for each request until one of them returns a successful response.
Installation
------------
1. Install the package::
.. code-block:: bash
$ pip install django-fallback-storage
2. Set ``fallback_storage.storage.FallbackStorage`` as your desired storage
backend.::
.. code-block:: python
# settings.py
DEFAULT_FILE_STORAGE = "fallback_storage.storage.FallbackStorage"
3. Declare what storage backends fallback storage should use.::
.. code-block:: python
# All operations will be tried first on `FileSystemStorage` and then on
# `S3BotoStorage`.
FALLBACK_STORAGES = (
"django.core.files.storage.FileSystemStorage",
"storages.backends.s3boto.S3BotoStorage",
)
API
---
``FallbackStorage`` implements all of the following backend methods.
* ``_open()``
* ``_save()``
* ``delete()``
* ``exists()``
* ``listdir()``
* ``size()``
* ``url()``
* ``accessed_time()``
* ``created_time()``
* ``modified_time()``
* ``get_valid_name()``
* ``get_available_name()``
* ``path()``
When one of these methods is called, each backend declared in
``FALLBACK_STORAGES`` is called. The first successful response is
returned.
Any backend which does not implement a given method will be skipped over. If
none of the backends implement a called method, then an ``AttributeError`` is
raised.
Exceptions raised by any backend are reraised if none of the backends returns a
successful response.
The following methods behave somewhat specially.
* **FallbackStorage.exists(name)**::
Will return ``True`` if the file exists in *any* of the storage backends.
* **FallbackStorage.listdir(path)**::
Will return the set of all directories and files in all of the storage backents.
* **FallbackStorage.url(name)**::
When computing a url, FallbackStorage first checks if the file exists. If
the file exists in none of the storage backends, the last backend is used to
compute the file name.
* **FallbackStorage.get_available_name(name)**::
When django attempts to get an available name for the file, FallbackStorage
checks the file name across all storage backends before returning an available
name. As such, each file will have a unique name across all storage backends in use.
django-fallback-storage
=======================
.. image:: https://badge.fury.io/py/django-fallback-storage.png
:target: https://badge.fury.io/py/django-fallback-storage
.. image:: https://travis-ci.org/pipermerriam/django-fallback-storage.png?branch=master
:target: https://travis-ci.org/pipermerriam/django-fallback-storage
``django-fallback-storage`` allows for the use of multiple storage engines at
the same time. It works by iterating through the declared storage backends
until one succeeds with the desired storage action.
While usable in a production environment, this tool was primarily designed to
help with development of a project.
Consider a production site using the ``S3BotoStorage`` backend to store its
static assets on Amazon S3 and a development environment that regularly gets
database dumps from the production environment. In order to get the media
associated with the database dump to work, the development environment could be
configured to use the same S3 bucket. This could be problematic, as it would
risk making unwanted modifications to the production media.
The ``FallbackStorage`` backend provided by ``django-fallback-storage`` allows
use of the same production production media source in the development
environment while delegating all write operations to a different storage
backend (such as the filesystem).
This is accomplished by wrapping multiple storage backends, and iterating
through them for each request until one of them returns a successful response.
Installation
------------
1. Install the package::
.. code-block:: bash
$ pip install django-fallback-storage
2. Set ``fallback_storage.storage.FallbackStorage`` as your desired storage
backend.::
.. code-block:: python
# settings.py
DEFAULT_FILE_STORAGE = "fallback_storage.storage.FallbackStorage"
3. Declare what storage backends fallback storage should use.::
.. code-block:: python
# All operations will be tried first on `FileSystemStorage` and then on
# `S3BotoStorage`.
FALLBACK_STORAGES = (
"django.core.files.storage.FileSystemStorage",
"storages.backends.s3boto.S3BotoStorage",
)
API
---
``FallbackStorage`` implements all of the following backend methods.
* ``_open()``
* ``_save()``
* ``delete()``
* ``exists()``
* ``listdir()``
* ``size()``
* ``url()``
* ``accessed_time()``
* ``created_time()``
* ``modified_time()``
* ``get_valid_name()``
* ``get_available_name()``
* ``path()``
When one of these methods is called, each backend declared in
``FALLBACK_STORAGES`` is called. The first successful response is
returned.
Any backend which does not implement a given method will be skipped over. If
none of the backends implement a called method, then an ``AttributeError`` is
raised.
Exceptions raised by any backend are reraised if none of the backends returns a
successful response.
The following methods behave somewhat specially.
* **FallbackStorage.exists(name)**::
Will return ``True`` if the file exists in *any* of the storage backends.
* **FallbackStorage.listdir(path)**::
Will return the set of all directories and files in all of the storage backents.
* **FallbackStorage.url(name)**::
When computing a url, FallbackStorage first checks if the file exists. If
the file exists in none of the storage backends, the last backend is used to
compute the file name.
* **FallbackStorage.get_available_name(name)**::
When django attempts to get an available name for the file, FallbackStorage
checks the file name across all storage backends before returning an available
name. As such, each file will have a unique name across all storage backends in use.
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-fallback-storage-1.1.1.tar.gz
.
File metadata
- Download URL: django-fallback-storage-1.1.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93571777e902f94e6fabbff8cfef5ac85850377e945bb32ed1a722722687626b |
|
MD5 | 453cfa7c1ab187ffe7b39fb487136052 |
|
BLAKE2b-256 | 53341875fcafd5ead0033ab89ddc8ff680f27fa04aca27293cf94d7c69b8a678 |
File details
Details for the file django_fallback_storage-1.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: django_fallback_storage-1.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85fe7653857ed94745e98c941863322caa2dd8b662b83f69a35f7a25940f25ab |
|
MD5 | bf299c1bb33665dbb5bf1c687d8f0a2f |
|
BLAKE2b-256 | f867918c7c8144e9c8c7d62821f3a0eb4e0fa162d9c5a4981ee868ac2c8e7f94 |