Skip to main content

Flask extension for HashFS, a content-addressable file management system.

Project description

version travis coveralls license

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.

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.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.

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

Flask-HashFS-0.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Flask_HashFS-0.2.0-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file Flask-HashFS-0.2.0.tar.gz.

File metadata

  • Download URL: Flask-HashFS-0.2.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-HashFS-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a318f3342c5221b78b331a0fb2a0f5cc11f8ea8c05e17e7cd425e071c7560cd6
MD5 2b4a291e9d5dafffed2c8c9233311bdf
BLAKE2b-256 0e93f0afc5233a4ab23c65af8f5ec807b6ce29fa8098352426afd342558eb844

See more details on using hashes here.

File details

Details for the file Flask_HashFS-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Flask_HashFS-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3f72450dd150fb25b6d3a6e95345abf50a4ae8d3a32a142da7a9c4ddbfd3e577
MD5 f135d62f80fd57ad9f8db2fb8514dad6
BLAKE2b-256 6aee9902a4b309dc475978643a9d91e98d13ae712ce319107b4b9508f18a611f

See more details on using hashes here.

Supported by

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