Giter VIP home page Giter VIP logo

flask-waffleconf's Introduction

Flask-WaffleConf PyPI version

WaffleConf is a Flask extension that enables storage of configuration variables in the database as well as runtime modification of said variables.

Released under GPLv2+ license.

Installation

$ pip install Flask-WaffleConf

Configuration

Simple usage of the extension requires the following configuration variables (e.g., in your application's config.py):

  • WAFFLE_CONFS: used for specifying the configuration variables that are going to be stored in the database. It has the following structure:
WAFFLE_CONFS = {
    'MAX_FILESIZE': {
        'desc': 'Max upload filesize (in bytes)',
        'default': 1000
    },

    'SITENAME': {
        'desc': 'Name of the site appearing in the header',
        'default': 'Waffle'
    }
}

Check the documentation for advanced usage

Example Application using SQLAlchemy as ORM

from flask import Flask, current_app
from flask_waffleconf import WaffleConf, AlchemyWaffleStore, \
    WaffleMixin
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['WAFFLE_CONFS'] = {
    'MAX_FILESIZE': {
        'desc': 'Max upload filesize (in bytes)',
        'default': 1000
    },

    'SITENAME': {
        'desc': 'Name of the site appearing in the header',
        'default': 'Waffle'
    }
}

# Define your database
# db = ...

# Define model
class ConfModel(db.Model, WaffleMixin):
    __tablename__ = 'confs'

    id = db.Column(db.Integer, primary_key=True)
    key = db.Column(db.String(255), unique=True)
    value = db.Column(db.Text)

# Create database tables
# ...

# Initialize WaffleConf
configstore = AlchemyWaffleStore(db=db, model=ConfModel)
waffle = WaffleConf(app, configstore)

@app.before_first_request
def do_before():
    """Update stored configurations."""
    waffle.state.update_conf()

@app.route('/')
def index():
    """Display content of configured variable 'SITENAME'."""
    state = current_app.extensions['waffleconf']

    parsed = state.parse_conf()
    # {'MAX_FILESIZE': 1000, 'SITENAME': 'Waffle'}

    return parsed['SITENAME']

Multiprocess deployments

Since version 0.2.0, multiprocess deployments are supported. Check the documentation for more information.

Documentation

Documentation is present in the docs/ directory and also online at https://flask-waffleconf.readthedocs.org. In order to build the documentation from source (you will need Sphinx), run the following command in the docs/ directory:

$ make html

flask-waffleconf's People

Contributors

rmed avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

flask-waffleconf's Issues

Initial Update

Hi ๐Ÿ‘Š

This is my first visit to this fine repo, but it seems you have been working hard to keep all dependencies updated so far.

Once you have closed this issue, I'll create separate pull requests for every update as soon as I find one.

That's it for now!

Happy merging! ๐Ÿค–

Multiple workers

Currently, the extension does not work with multiple workers, resulting in inconsistencies in the configurations of the different app instances.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.