Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Asset storage for Flask

Project Description
# Lagring: asset storage for Flask

## Requirements

- SQLAlchemy
- Flask
- PostgreSQL 9.4+

## Installation

pip install lagring

If you want to use `ImageAsset` class you have to install Pillow as well.

## How to use it

0. Configure your Flask app to have necessary config options:

Parameter | Meaning
ASSET_STORAGE_ROOT | Path to the directory where assets will be stored
ASSET_URL_ROOT | Asset URL invariable part

1. Create storage instance:

from lagring import FlaskLagring

storage = FlaskLagring()

2. Derive your SQLAlchemy model from `storage.Entity` class:

from lagring import Asset

class File(db.Model, storage.Entity):
id = db.Column(db.Integer, primary_key=True)
file = Asset()

Note that JSONB field `_assets` will be added to the model (PostgreSQL 9.4+).
You can change the name by overriding `lagring.Entity.asset_data_field` method.

3. Put something to that asset field:

new_file = File()
new_file.file = '/some/local/path/filename'

The model instance must have a valid id on asset assignment, so you have to call `flush()`
before that.

4. Then you can use the asset like this:

# get asset URL
url = new_file.file.url
# get asset path
path = new_file.file.abs_path
# delete the asset
del new_file.file

5. Besides the basic `Asset` class, there are also `ImageAsset` and `DirectoryAsset` to store
something more specific and have some processing on upload (no docs for that yet, please see
the code).
Release History

Release History

This version
History Node

History Node


History Node

History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Lagring- (9.8 kB) Copy SHA256 Checksum SHA256 Source Jul 22, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting