A clean abstraction over cloud file storage platforms like S3, Alicloud, or Heroku.
Project description
Simple cloud file storage for Flask applications on platforms like S3, Alicloud, or Heroku.
import os
from flask import Flask
from flask_warehouse import Warehouse
# 1. Configuring Warehouse
app = Flask(__name__)
app.config['WAREHOUSE_DEFAULT_SERVICE'] = 's3' # or 'file' for filesystem
app.config['WAREHOUSE_DEFAULT_LOCATION'] = 'us-west-1' # required for 's3'
app.config['WAREHOUSE_DEFAULT_BUCKET'] = None
app.config['AWS_ACCESS_KEY_ID'] = '...' # required for 's3'
app.config['AWS_SECRET_ACCESS_KEY'] = '...' # required for 's3'
warehouse = Warehouse(app)
# Object-oriented approach:
bucket = warehouse.bucket('mybucket')
oo_cubby = bucket.cubby('keys')
# Or compact approach:
compact_cubby = warehouse('s3:///mybucket/keys')
assert oo_cubby == compact_cubby
cubby = oo_cubby
# 2. Writing to/from bytes
contents = b'12345'
cubby.store(bytes=contents)
assert cubby.filesize() == 5
cubby_contents = cubby.retrieve()
assert cubby_contents == contents
# 3. Writing to/from files
filepath = "local.txt"
with open(filepath, 'wb') as f:
f.write(b"Here are the contents of a file.")
cubby.store(filepath=filepath)
assert os.path.getsize(filepath) == cubby.filesize()
assert cubby.retrieve() == open(filepath, 'rb').read()
```
History
0.1.0 (2019-03-26)
First release on PyPI.
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
flask_warehouse-0.1.12.tar.gz
(17.6 kB
view details)
Built Distribution
File details
Details for the file flask_warehouse-0.1.12.tar.gz
.
File metadata
- Download URL: flask_warehouse-0.1.12.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7347c099e348c993527b7070fc35c5991ceb1280f08815c49e4fdb2c32e239aa |
|
MD5 | fdb8826f31381c356b0d64530ad40079 |
|
BLAKE2b-256 | 48282d6e0d3cc86d678301775b8c3bbe2b0e57f019fde30c22c79d0582b8082d |
File details
Details for the file flask_warehouse-0.1.12-py2.py3-none-any.whl
.
File metadata
- Download URL: flask_warehouse-0.1.12-py2.py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d4157867066bd471f8674b2c25466ce70fe6f23a2389b44fa7970895c547fee |
|
MD5 | 3fbc3e81723dfe477d59b15bd8fce296 |
|
BLAKE2b-256 | 346f209980c861dee22b263faecebcf80fd724396ca9bcd4a46a57f16b25e442 |