Skip to main content

Store certain configuration variables in database

Project description

Flask-WaffleConf PyPI version

A Flask extension that enables storage of configuration variables in the database as well as runtime modification of these variables.

Released under GPLv2+ license.

Installation

$ pip install Flask-WaffleConf

Configuration

The extension uses the following configuration variables:

  • WAFFLE_CONFS: Used for specifying the configuration variables that are going to be stored in the database. It has the following structure:

WAFFLE_CONFS = {
    'CONF_VAR1': {
        'type': 'str',
        'desc': 'First config var',
        'default': '0'
    },
    'CONF_VAR2': {
        'type': 'int',
        'desc': 'Second config var',
        'default': '0'
    }
}
  • WAFFLE_TEMPLATE: Template containing the form used for updating the configuration values. You are highly encouraged to extend the default template.

  • WAFFLE_MULTIPROC: Set it to True in order to enable multiprocess use (check the documentation)

  • WAFFLE_REDIS_HOST: Redis host to use for notifications.

  • WAFFLE_REDIS_PORT: Port to use for the Redis connection.

  • WAFFLE_REDIS_CHANNEL: Channel to use for the notifications.

Example Application using peewee as ORM

from flask import Flask
from flask.ext.waffleconf import WaffleConf, PeeweeWaffleStore, \
    WaffleMixin, register_waffle
import peewee

app = Flask(__name__)
app.config['WAFFLE_CONFS'] = {
    'CONF_VAR1': {
        'type': 'str',
        'desc': 'First config var',
        'default': '0'
    },
    'CONF_VAR2': {
        'type': 'int',
        'desc': 'Second config var',
        'default': '0'
    }
}

# Define your database
# db = ...

# Define model
class ConfModel(peewee.model, WaffleMixin):
    class Meta:
        database = db

    key = peewee.CharField(unique=True)
    value = peewee.TextField()

# Create database tables
# ...

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

# Plug the WaffleConf view to any of your Blueprints
register_waffle(app, 'waffleconf', '/config')

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 MkDocs), run:

$ mkdocs build

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-WaffleConf-0.2.0.tar.gz (18.6 kB view hashes)

Uploaded Source

Built Distribution

Flask_WaffleConf-0.2.0-py2.py3-none-any.whl (13.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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