Skip to main content

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/simpleenergy/django-fallback-storage.png?branch=master
:target: https://travis-ci.org/simpleenergy/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.

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

django-fallback-storage-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

django_fallback_storage-1.0.0-py2.py3-none-any.whl (6.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-fallback-storage-1.0.0.tar.gz.

File metadata

File hashes

Hashes for django-fallback-storage-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ce61769dc6986d978e73c529510d7d1e719ad87f53392f3d6de0c1cf43423e85
MD5 9cac1f4100bede9ae23f2405d6f37284
BLAKE2b-256 db0f87fc8cd7a8187a845d57aa0c9ada3f5d511a32787415cf4d4710dbcab555

See more details on using hashes here.

File details

Details for the file django_fallback_storage-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_fallback_storage-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 645ad6390a63e84f2b05a5f4a430b46a1924da3d5d23767270b9f581750888ab
MD5 006f22585f2f6f7c010f9ed1cf4efe4b
BLAKE2b-256 18c05d47ed30822fe6ee3be5adf35e90aff9e9efa22790634943455de3b37d0f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page