Toolkit for storing files and attachments in web applications
.. image:: https://raw.github.com/amol-/depot/master/docs/_static/logo.png
.. image:: https://travis-ci.org/amol-/depot.png?branch=master :target: https://travis-ci.org/amol-/depot
.. image:: https://coveralls.io/repos/amol-/depot/badge.png?branch=master :target: https://coveralls.io/r/amol-/depot?branch=master
.. image:: https://img.shields.io/pypi/v/filedepot.svg :target: https://pypi.python.org/pypi/filedepot
DEPOT is a framework for easily storing and serving files in web applications on Python2.6+ and Python3.2+.
DEPOT supports storing files in multiple backends, like:
* Local Disk * In Memory (for tests) * On GridFS * On Amazon S3 (or compatible services)
and integrates with database by providing files attached to your SQLAlchemy or Ming/MongoDB models with respect to transactions behaviours (files are rolled back too).
Installing DEPOT can be done from PyPi itself by installing the
filedepotdistribution::
$ pip install filedepot
To start using Depot refer to
Documentation_
DEPOT was
presented at PyConUK and PyConFR_ in 2014
standalone ~~~~~~~~~~
Here is a simple example of using depot standalone to store files on MongoDB::
from depot.manager import DepotManagerConfigure a default depot to store files on MongoDB GridFS
DepotManager.configure('default', { 'depot.backend': 'depot.io.gridfs.GridFSStorage', 'depot.mongouri': 'mongodb://localhost/db' })
depot = DepotManager.get()
Save the file and get the fileid
fileid = depot.create(open('/tmp/file.png'))
Get the file back
stored_file = depot.get(fileid) print stored_file.filename print stored_file.content_type
models ~~~~~~
Or you can use depot with SQLAlchemy to store attachments::
from depot.fields.sqlalchemy import UploadedFileField from depot.fields.specialized.image import UploadedImageWithThumbclass Document(Base): tablename = 'document'
uid = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(16), unique=True) content = Column('content_col', UploadedFileField) # plain attached file # photo field will automatically generate thumbnail photo = Column(UploadedFileField(upload_type=UploadedImageWithThumb))
Store documents with attached files, the source can be a file or bytes
doc = Document(name=u'Foo', content=b'TEXT CONTENT STORED AS FILE', photo=open('/tmp/file.png')) DBSession.add(doc) DBSession.flush()
DEPOT is session aware, commit/rollback to keep or delete the stored files.
DBSession.commit()
0.8.0 ~~~~~
unidecodedependency with
anyasciito better cope with MIT License.
0.7.1 ~~~~~
0.7.0 ~~~~~
storage_classoption in
depot.io.boto3.S3Storagebackend. Detaults to
STANDARD
0.6.0 ~~~~~
/depotsomethingwas wrongly served for
/depotmountpoint)
Relationship.remove(IE:
parent.children.remove(X))
cascade='delete-orphan'
0.5.2 ~~~~~
0.5.1 ~~~~~
DepotMiddlewareare now guaranteed to be plain ascii
s3:ListAllMyBucketsthat wasn't required on 0.5.0
0.5.0 ~~~~~
depot.io.boto3.S3Storagenow provides support for accessing S3 with
boto3. The previously existing
depot.io.awss3.S3Storagecan still be used to store files on S3 using
boto.
toxand build docs through
tox -e docs
0.4.1 ~~~~~
0.4.0 ~~~~~
Content-Dispositionheader for filenames including a comma
0.3.2 ~~~~~
MemoryFileStoragenow accepts any option, for easier testing configuration
0.3.1 ~~~~~
Content-Dispositionheader when serving from S3 directly
0.3.0 ~~~~~
MemoryFileStorageprovides in memory storage for files. This is meant to provide a convenient way to speed up test suites and avoid fixture clean up issues.
0.2.1 ~~~~~
S3Storagenow supports the
prefixoption to store files in a subpath
0.2.0 ~~~~~
listmethod to list files available on the store (This is not meant to be used to retrieve files uploaded by depot as it lists all the files).
DepotExtensionfor Ming is now properly documented
0.1.2 ~~~~~
WithThumbnailFilterto generate multiple thumbnails with different resolutions.
UploadedFileProperty
0.1.1 ~~~~~
UploadedFilePropertyas a class property
0.1.0 ~~~~~
DepotManager.aliasto configure aliases to storage. This allows easy migration from one storage to another by switching where the alias points.
UploadedFileFieldpermits to specify
upload_storageto link a Model Column to a specific storage.
policyand
encrypt_keyoptions to
S3Storageto upload private and encrypted files.
0.0.6 ~~~~~
hostoption to
S3Storageto allow using providers different from AWS.
0.0.5 ~~~~~
FileIntentto explicitly provide
content_typeand
filenameto uploaded content.
0.0.4 ~~~~~
0.0.3 ~~~~~
wsgi.file_wrapperprovided by Waitress WSGI Server
0.0.2 ~~~~~