Flask-HashFS
Flask extension for HashFS, a content-addressable file management system.
What is HashFS?
HashFS is a content-addressable file management system. What does that mean? Simply, that HashFS manages a directory where files are saved based on the file’s hash.
Typical use cases for this kind of system are ones where:
Files are written once and never change (e.g. image storage).
It’s desirable to have no duplicate files (e.g. user uploads).
File metadata is stored elsewhere (e.g. in a database).
What is Flask-HashFS?
Flask-HashFS is a Flask extension that integrates HashFS into the Flask ecosystem.
Links
Documentation: http://flask-hashfs.readthedocs.org
Quickstart
Install using pip:
pip install Flask-HashFS
Initialization
from flask import Flask
from flask_hashfs import FlaskHashFS
app = Flask(__name__)
fs = FlaskHashFS()
Configure Flask-HashFS to store files in /var/www/data/uploads and give them a route prefix at /uploads.
app.config.update({
'HASHFS_HOST': None,
'HASHFS_PATH_PREFIX': '/uploads',
'HASHFS_ROOT_FOLDER': '/var/www/data/uploads',
'HASHFS_DEPTH': 4,
'HASHFS_WIDTH': 1,
'HASHFS_ALGORITHM': 'sha256'
})
fs.init_app(app)
Usage
Use Flask-HashFS to manage files using HashFS.
with app.app_context():
# Store readable objects or file paths
address = fs.put(io_obj, extension='.jpg')
# Get a file's hash address
assert fs.get(address.id) == address
assert fs.get(address.relpath) == address
assert fs.get(address.abspath) == address
assert fs.get('invalid') is None
# Get a BufferedReader handler
fileio = fs.open(address.id)
# Or using the full path...
fileio = fs.open(address.abspath)
# Or using a path relative to fs.root
fileio = fs.open(address.relpath)
# Delete a file by address ID or path
fs.delete(address.id)
fs.delete(address.abspath)
fs.delete(address.relpath)
For direct access to the HashFS instance, use the client attribute.
fs.client
assert isinstance(fs.client, flask_hashfs.HashFS)
Generate URLs for HashFS content.
with app.test_request_context():
fs.url_for('relative/file/path')
For more details, please see the full documentation at http://flask-hashfs.readthedocs.org and http://hashfs.readthedocs.org.
Changelog
v0.3.0 (2015-06-03)
Replace manual proxy access of HashFS methods with single __getattr__ method.
v0.2.0 (2015-06-02)
Pin hashfs dependency to >=0.3.0. (breaking change)
Rename config key HASHFS_LENGTH to HASHFS_WIDTH to be in alignment with hashfs>=0.3.0. (breaking change)
v0.1.0 (2015-06-02)
First release.
Add FlaskHashFS.put.
Add FlaskHashFS.get.
Add FlaskHashFS.open.
Add FlaskHashFS.delete.
Add FlaskHashFS.url_for.
Metadata
Release files for Flask-HashFS 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-HashFS-0.3.0.tar.gz | 16.0 kB | Without provenance | Details for Flask-HashFS-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_HashFS-0.3.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for Flask_HashFS-0.3.0-py2.py3-none-any.whl |
Total release size: 23.7 kB
Release files / Flask-HashFS-0.3.0.tar.gz
| Download URL | Flask-HashFS-0.3.0.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47514beef005b5895f954c0e6bafcdb0cc6c819c947d6d57a84914fc901d9cfd
|
|
BLAKE2b-256 checksum How to use checksums |
0ec2d69f969e0066ce6adc66682822af62949c72edf24f5341fe0a8023b9afaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / Flask_HashFS-0.3.0-py2.py3-none-any.whl
| Download URL | Flask_HashFS-0.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f5e1d77917013e5e94c1010a709c47a8c18602e11a851c9e84b68cfb0c1ac043
|
|
BLAKE2b-256 checksum How to use checksums |
a4174e615704add3c43355943010ed7c32d95c2e99c6c8a9fce8d07e5a8427d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for Flask-HashFS 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.