Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mozillazg/flask-envconfig
Extension for configuring Flask from environment variables.
https://github.com/mozillazg/flask-envconfig
Last synced: 22 days ago
JSON representation
Extension for configuring Flask from environment variables.
- Host: GitHub
- URL: https://github.com/mozillazg/flask-envconfig
- Owner: mozillazg
- License: other
- Created: 2016-02-14T13:05:25.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-14T13:05:30.000Z (almost 9 years ago)
- Last Synced: 2024-10-03T15:42:24.752Z (3 months ago)
- Language: Python
- Homepage: https://bitbucket.org/romabysen/flask-envconfig
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
About
-----
Extension for configuring Flask from environment variables.Requirements
------------
* FlaskInstallation
------------::
pip install flask-envconfig
Usage
-----
Simple usage:::
from flask import Flask
from flask.ext.envconfig import EnvConfigapp = Flask(__name__)
env = EnvConfig(app)Or, for the application factory pattern:
::
env = EnvConfig()
# At a later time
env.init_app(app)Now set your configuration variables in your shell, .env file or whatever:
::
FLASK_DEBUG=True
FLASK_SECRET_KEY="Something_or_the_other"By default only environments variables prefixed with FLASK\_ are processed and added to app.config. The extension strips off the prefix so FLASK_DEBUG becomes app.config['DEBUG'] and so forth.
The extension understands "True" to mean True, "False" to mean False and "None" to mean None. It also understands lists, tuples and dicts and numbers.::
FLASK_TRUE=True
FLASK_FALSE=False
FLASK_NONE=None
FLASK_INTEGER=1
FLASK_FLOAT=1.1
FLASK_STRING="This is a string"
FLASK_LIST="['a', 'b', 'c']"
FLASK_TUPLE="('a', 'b', 'c')"
FLASK_DICT="{'a': 1, 'b': 6}"The prefix can be changed if so desired:
::
EnvConfig(app, 'MYPREFIX_')
Or
::
env = EnvConfig()
env.init_app(app, 'MYPREFIX_')