https://github.com/nzac/flask-environment
A configuration library for Flask with support for TOML
https://github.com/nzac/flask-environment
configuration-by-environment flask flask-environment python toml
Last synced: 4 months ago
JSON representation
A configuration library for Flask with support for TOML
- Host: GitHub
- URL: https://github.com/nzac/flask-environment
- Owner: nZac
- License: mit
- Created: 2015-07-05T21:59:09.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-24T15:50:06.000Z (over 9 years ago)
- Last Synced: 2025-03-17T15:18:21.977Z (over 1 year ago)
- Topics: configuration-by-environment, flask, flask-environment, python, toml
- Language: Python
- Homepage:
- Size: 22.5 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
Flask-Environment
#################
.. image:: https://circleci.com/gh/nZac/flask-environment/tree/master.svg?style=svg
:target: https://circleci.com/gh/nZac/flask-environment/tree/master
Configure a Flask applications with various configuration formats.
Version
-------
0.1.0
Description
-----------
Configure Flask applications with other file formats like TOML. The killer
feature of Flask-Environment is the ability to adjust settings without multiple
configuration files.
Supports Python 2.7, 3.4, 3.5.
Installation
------------
.. code::
$ pip install flask-environment
.. code::
$ pip install flask-environment[TOML]
Usage Flask>0.10
----------------
.. code::
import flask
from flask_environment import Config
class MyApp(flask.Flask):
config_class = Config
app = MyApp(__name__)
app.config.from_toml('config.toml')
Environments
------------
Flask-Environment adds the idea of environments to a configuration file. For
different situations you might change the configuration even when the
application is deployed to the same machine, this is most helpful with testing.
You probably want to use a different database for testing than what you do for
regular development.
Flask-Environment solves this problem with the concept of environments. Within a
configuration file, create a new dict called ``environments`` with the keys being
the name of the different environments you intend to declare.
Activate an environment like this:
.. code::
app.config.from_toml('config.toml', environment='testing')
This will load all the default settings (everything not in an environment)
and then the specified environment. Here is a sample TOML file demonstrating the
idea.
.. code::
SUPER_COOL_FEATURE = true
DEBUG = false
[environments.dev]
DEBUG = true
[environments.testing]
TESTING = true
If we loaded the ``dev``` environment, the application debug flag would be set to
``True`` and ``SUPER_COOL_FEATURE`` would be available.
While you could use this to provision different logical environments in the same
file (beta, production) there really isn't a point. Environments are for
changing configurations within the same logical environments. Maybe you have a
production environment that spawns two apps that need two diverging
configurations, environments fill that need.
Licence
-------
MIT