Skip to main content

flask-config-override

[![Build Status](https://travis-ci.org/elboby/flask-config-override.png?branch=master)](https://travis-ci.org/elboby/flask-config-override)

This extension allows to change the configuration of a Flask application at runtime. This behavior is controlled by cookie and therefore is contained to the session of an unique user; configuration changes are not affecting other users.

A common usage is to quickly change options in staging environment without having to redeploy configuration changes. For example, we use it for an external API location or a feature switch like using minified Javascript files or not.

The configuration options able to be overridden are limited and configurable as well (using CONFIG_OVERRIDE_EXTENDABLE_VARS). This option can NOT be overridden for security reason.

The idea is to replace the configuration object of a Flask application by a proxy object, whom behavior can be controlled/changed upon request while exposing the same interface as a Flask configuration. The extension also provide a blueprint (default base url to /config_override/) to control the cookie via some simple HTTP calls; this is automatically attached to the application.

Installation

Via Pypi:

pip install flask-config-override

Usage

Once installed, first attach the extension to your Flask application:

from flask import Flask from flask.ext.config_override import ConfigOverride

app = Flask(__name__) app.config[‘FOO’] = ‘bar’

# Enable the override for the DEBUG option (default to false) app.config[‘CONFIG_OVERRIDE_EXTENDABLE_VARS’] = [‘FOO’] config_override = ConfigOverride(app)

# configure your routes and what not…

Launch your app, then open your browser and go to this url to setup the FOO option to another value; here “toto”:

http://localhost:5000/config_override/update/FOO/toto/

Your session will now run with the settings FOO set to the new value. You can access it normally from app.config[‘FOO’] within the context of a request.

To see the current changes, you can visit this url:

http://localhost:5000/config_override/

And to remove the changes, you just need to clear your cookie or go there:

http://localhost:5000/config_override/reset/

Tests

  • First install nose for test discovery: pip install nose

  • Then run the tests within a virtual environment: nosetests

Contact

Feel free to post issues, pull requests in github or contact me directly on twitter @el_boby.

Immediate TODOs

  • test for cookie_utils

  • test for proxy_config (based on flask one)

  • documentation API (sphinx)

TODO

  • Override by Environment variables.

  • Flask Debug Toolbar integration.

Metadata

Release files for Flask-Config-Override 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Config-Override 0.0.2
File Size Uploaded
Flask-Config-Override-0.0.2.tar.gz 5.3 kB Details

Release files / Flask-Config-Override-0.0.2.tar.gz

Download URL Flask-Config-Override-0.0.2.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f35e88e9cf36aad8bac0c5c7bdc49229f7785ab61a01a643012c5e344aa1d6dc
BLAKE2b-256 checksum
How to use checksums
2f181e396d94f8ff2a8ec0098ff9fc5f350aaff147831bc7bd6b58c9f2d3914e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page