Flask-AppConfig
===============
Allows you to configure an application using pre-set methods.
.. code-block:: python
from flask_appconfig import AppConfig
def create_app(configfile=None):
app = Flask('myapp')
AppConfig(app, configfile)
return app
The application returned by ``create_app`` will, in order:
1. Load default settings from a module called ``myapp.default_config``, if it
exists. (method described in
http://flask.pocoo.org/docs/config/#configuring-from-files )
2. Load settings from a configuration file whose name is given in the
environment variable ``MYAPP_CONFIG`` (see link from 1.).
3. Load json or string values directly from environment variables that start
with a prefix of ``MYAPP_``, i.e. setting ``MYAPP_SQLALCHEMY_ECHO=true``
will cause the setting of ``SQLALCHEMY_ECHO`` to be ``True``.
Any of these behaviors can be altered or disabled by passing the appropriate
options to the constructor or ``init_app()``.
Heroku support
--------------
Flask-AppConfig supports configuring a number of services through
``HerokuConfig``:
.. code-block:: python
from flask_appconfig import HerokuConfig
def create_app(configfile=None):
app = Flask('myapp')
HerokuConfig(app, configfile)
return app
Works like the example above, but environment variables set by various Heroku
addons will be parsed as json and converted to configuration variables
accordingly. Forexample, when enabling `Mailgun
<https://addons.heroku.com/mailgun>`_, the configuration of `Flask-Mail
<http://pythonhosted.org/Flask-Mail/>`_ will be automatically be set correctly.
Using "ENV-only"
----------------
If you only want to use the environment-parsing functions of Flask-AppConfig,
the appropriate functions are exposed:
.. code-block:: python
from flask_appconfig.heroku import from_heroku_envvars
from flask_appconfig.env import from_envvars
# from environment variables. note that you need to set the prefix, as
# no auto-detection can be done without an app object
from_envvars(app.config, prefix=app.name.upper() + '_')
# also possible: parse heroku configuration values
# any dict-like object will do as the first parameter
from_heroku_envvars(app.config)
Installation
------------
Via `PyPI <http://pypi.python.org/pypi/flask-appconfig>`_::
$ pip install flask-appconfig
Requires Python 2.7.
flask utility
-------------
If you want to get started quickly without thinking a lot about writing a run
script, the ``flask`` utility supports the ``create_app``/factory pattern::
$ flask --app=myapp dev
This will import a module ``myapp``, and call ``myapp.run(debug=True)``.
Other options can come in handy as well::
$ flask --app=myapp dev -S -p 8000
Runs the app on port 8080, with SSL enabled. You can also set the ``FLASK_APP``
environment variable or set ``FLASK_APP`` inside ``.env`` and omit the
``--app`` parameter.
Note that the ``flask`` utility is subject to change, as it will conflict with
the CLI functionality of Flask 1.0. The API is currently kept close, but it
will see changes once Flask 1.0 is released.
Flask-Debug and Flask-DebugToolbar support
******************************************
``flask`` automatically activates Flask-Debug_ and Flask-DebugToolbar_ on
your application; this allows to have it installed locally while not having to
install any debug code in production. You can suppress this behavior with the
``-E``/``--no-flask-debug`` flag.
Note that these features are only enabled if you install either of these
extensions manually; they are not dependencies of Flask-Appconfig.
.. _Flask-Debug: https://github.com/mbr/flask-debug
.. _Flask-DebugToolbar: https://flask-debugtoolbar.readthedocs.org/
Thoughts on Configuration
-------------------------
There is a lot of ways to configure a Flask application and often times,
less-than-optimal ones are chosen in a hurry.
This extension aims to do three things:
1. Set a "standard" of doing configuration that is flexible and in-line with
the official docs and (what I consider) good practices.
2. Make it as convenient as possible to provide these configuration methods in
an application.
3. Auto-configure on Heroku as much as possible without sacrificing 1. and 2.
`12factor.net <http://12factor.net/>`_ seems to capture a good amount of good
thoughts on the issue and Flask-Appconfig should aid you in writing an
application that follows the principles laid out there.
Providing defaults
******************
Defaults should be included and overridable, without altering the file
containing the defaults.
Separate code and configuration
*******************************
It should be possible to install the app to a read-only (possibly system-wide)
location, without having to store configuration files (or, even worse,
configuration modules) inside its folders.
Environment variables and instance folders make this possible. As an added
benefit, configuration does not need to be stored alongside the code in version
control.
No code necessary for most deployments using the factory-method pattern
***********************************************************************
When deploying with gunicorn, passing ``myapp:create_app()`` suffices to create
an app instance, no boilerplate code to create the WSGI app should be necessary.
Multiple instances
******************
Running multiple apps inside the same interpreter should also be possible. While
this is slightly more complicated and may occasionally violate the "no-code"
guideline above, it's still straightforward by using configuration file
parameters.
Development
-----------
Flask-AppConfig is under "conceptional development". The API or semantics
may change in the future.
Send pull requests for more Heroku-apps to be supported. Send feedback via mail.
Changelog
---------
Backwards-incompatible changes, as they were introduced:
0.12
****
* The ``configfile``-parameter has been deprecated.
* Auto-discovery has been removed, pending decision on
https://github.com/mitsuhiko/flask/pull/1536
0.11
****
* The ``flaskdev`` tool has been replaced with ``flask``.
* Using the new ``flask`` tool auto-reloading will also change by default. If a
syntax error is introduced to the code, the app will try to restart after two
seconds by default, instead of crashing. This can be suppressed with the
'--extended-reload 0' flag.
* If the app import fails, ``flask`` will add ``.`` to ``sys.path`` and try to
to import once again.
* Experimental commands ``serve`` and ``db`` have been added.
0.4
***
* Environment variables are no longer prefixed with ``FLASK_`` by default, but
rather use ``APPNAME_`` (with ``APPNAME`` being the applications name in
uppercase).
* ``MYAPP_SETTINGS`` became ``MYAPP_CONFIG``, ``default_settings`` became
``default_config``.
Raw data
{
"_id": null,
"home_page": "http://github.com/mbr/flask-appconfig",
"name": "flask-appconfig-current",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Marc Brinkmann",
"author_email": "git@marcbrinkmann.de",
"download_url": "https://files.pythonhosted.org/packages/0d/e2/bf703cc343b560f81d814b3b3a514e6cf8a81dd54ce030945789e53c52cb/flask-appconfig-current-0.13.2.tar.gz",
"platform": null,
"description": "Flask-AppConfig\n===============\n\nAllows you to configure an application using pre-set methods.\n\n.. code-block:: python\n\n from flask_appconfig import AppConfig\n\n def create_app(configfile=None):\n app = Flask('myapp')\n AppConfig(app, configfile)\n return app\n\nThe application returned by ``create_app`` will, in order:\n\n1. Load default settings from a module called ``myapp.default_config``, if it\n exists. (method described in\n http://flask.pocoo.org/docs/config/#configuring-from-files )\n2. Load settings from a configuration file whose name is given in the\n environment variable ``MYAPP_CONFIG`` (see link from 1.).\n3. Load json or string values directly from environment variables that start\n with a prefix of ``MYAPP_``, i.e. setting ``MYAPP_SQLALCHEMY_ECHO=true``\n will cause the setting of ``SQLALCHEMY_ECHO`` to be ``True``.\n\nAny of these behaviors can be altered or disabled by passing the appropriate\noptions to the constructor or ``init_app()``.\n\n\nHeroku support\n--------------\n\nFlask-AppConfig supports configuring a number of services through\n``HerokuConfig``:\n\n.. code-block:: python\n\n from flask_appconfig import HerokuConfig\n\n def create_app(configfile=None):\n app = Flask('myapp')\n HerokuConfig(app, configfile)\n return app\n\nWorks like the example above, but environment variables set by various Heroku\naddons will be parsed as json and converted to configuration variables\naccordingly. Forexample, when enabling `Mailgun\n<https://addons.heroku.com/mailgun>`_, the configuration of `Flask-Mail\n<http://pythonhosted.org/Flask-Mail/>`_ will be automatically be set correctly.\n\n\nUsing \"ENV-only\"\n----------------\n\nIf you only want to use the environment-parsing functions of Flask-AppConfig,\nthe appropriate functions are exposed:\n\n.. code-block:: python\n\n from flask_appconfig.heroku import from_heroku_envvars\n from flask_appconfig.env import from_envvars\n\n # from environment variables. note that you need to set the prefix, as\n # no auto-detection can be done without an app object\n from_envvars(app.config, prefix=app.name.upper() + '_')\n\n # also possible: parse heroku configuration values\n # any dict-like object will do as the first parameter\n from_heroku_envvars(app.config)\n\n\nInstallation\n------------\n\nVia `PyPI <http://pypi.python.org/pypi/flask-appconfig>`_::\n\n $ pip install flask-appconfig\n\nRequires Python 2.7.\n\n\nflask utility\n-------------\n\nIf you want to get started quickly without thinking a lot about writing a run\nscript, the ``flask`` utility supports the ``create_app``/factory pattern::\n\n $ flask --app=myapp dev\n\nThis will import a module ``myapp``, and call ``myapp.run(debug=True)``.\n\nOther options can come in handy as well::\n\n $ flask --app=myapp dev -S -p 8000\n\nRuns the app on port 8080, with SSL enabled. You can also set the ``FLASK_APP``\nenvironment variable or set ``FLASK_APP`` inside ``.env`` and omit the\n``--app`` parameter.\n\nNote that the ``flask`` utility is subject to change, as it will conflict with\nthe CLI functionality of Flask 1.0. The API is currently kept close, but it\nwill see changes once Flask 1.0 is released.\n\n\nFlask-Debug and Flask-DebugToolbar support\n******************************************\n\n``flask`` automatically activates Flask-Debug_ and Flask-DebugToolbar_ on\nyour application; this allows to have it installed locally while not having to\ninstall any debug code in production. You can suppress this behavior with the\n``-E``/``--no-flask-debug`` flag.\n\nNote that these features are only enabled if you install either of these\nextensions manually; they are not dependencies of Flask-Appconfig.\n\n.. _Flask-Debug: https://github.com/mbr/flask-debug\n.. _Flask-DebugToolbar: https://flask-debugtoolbar.readthedocs.org/\n\n\nThoughts on Configuration\n-------------------------\n\nThere is a lot of ways to configure a Flask application and often times,\nless-than-optimal ones are chosen in a hurry.\n\nThis extension aims to do three things:\n\n1. Set a \"standard\" of doing configuration that is flexible and in-line with\n the official docs and (what I consider) good practices.\n2. Make it as convenient as possible to provide these configuration methods in\n an application.\n3. Auto-configure on Heroku as much as possible without sacrificing 1. and 2.\n\n`12factor.net <http://12factor.net/>`_ seems to capture a good amount of good\nthoughts on the issue and Flask-Appconfig should aid you in writing an\napplication that follows the principles laid out there.\n\nProviding defaults\n******************\n\nDefaults should be included and overridable, without altering the file\ncontaining the defaults.\n\nSeparate code and configuration\n*******************************\n\nIt should be possible to install the app to a read-only (possibly system-wide)\nlocation, without having to store configuration files (or, even worse,\nconfiguration modules) inside its folders.\n\nEnvironment variables and instance folders make this possible. As an added\nbenefit, configuration does not need to be stored alongside the code in version\ncontrol.\n\nNo code necessary for most deployments using the factory-method pattern\n***********************************************************************\n\nWhen deploying with gunicorn, passing ``myapp:create_app()`` suffices to create\nan app instance, no boilerplate code to create the WSGI app should be necessary.\n\nMultiple instances\n******************\n\nRunning multiple apps inside the same interpreter should also be possible. While\nthis is slightly more complicated and may occasionally violate the \"no-code\"\nguideline above, it's still straightforward by using configuration file\nparameters.\n\n\nDevelopment\n-----------\nFlask-AppConfig is under \"conceptional development\". The API or semantics\nmay change in the future.\n\nSend pull requests for more Heroku-apps to be supported. Send feedback via mail.\n\nChangelog\n---------\n\nBackwards-incompatible changes, as they were introduced:\n\n0.12\n****\n* The ``configfile``-parameter has been deprecated.\n* Auto-discovery has been removed, pending decision on\n https://github.com/mitsuhiko/flask/pull/1536\n\n0.11\n****\n* The ``flaskdev`` tool has been replaced with ``flask``.\n* Using the new ``flask`` tool auto-reloading will also change by default. If a\n syntax error is introduced to the code, the app will try to restart after two\n seconds by default, instead of crashing. This can be suppressed with the\n '--extended-reload 0' flag.\n* If the app import fails, ``flask`` will add ``.`` to ``sys.path`` and try to\n to import once again.\n* Experimental commands ``serve`` and ``db`` have been added.\n\n0.4\n***\n* Environment variables are no longer prefixed with ``FLASK_`` by default, but\n rather use ``APPNAME_`` (with ``APPNAME`` being the applications name in\n uppercase).\n* ``MYAPP_SETTINGS`` became ``MYAPP_CONFIG``, ``default_settings`` became\n ``default_config``.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Configures Flask applications in a canonical way. Also auto-configures Heroku. Aims to standardize configuration.",
"version": "0.13.2",
"project_urls": {
"Homepage": "http://github.com/mbr/flask-appconfig"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b450813484b637f0dbb85bbc6fdaccaf93b573aedd5be805cbf4b84dfbc50775",
"md5": "bf7d5d7e4ca2fd493a082dd8c3bc69ee",
"sha256": "2fed6e61a67879a5aba98ab18995734a6a9b0e9d5fab0e702435b136053d4c81"
},
"downloads": -1,
"filename": "flask_appconfig_current-0.13.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bf7d5d7e4ca2fd493a082dd8c3bc69ee",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 15044,
"upload_time": "2023-09-24T21:40:44",
"upload_time_iso_8601": "2023-09-24T21:40:44.869261Z",
"url": "https://files.pythonhosted.org/packages/b4/50/813484b637f0dbb85bbc6fdaccaf93b573aedd5be805cbf4b84dfbc50775/flask_appconfig_current-0.13.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0de2bf703cc343b560f81d814b3b3a514e6cf8a81dd54ce030945789e53c52cb",
"md5": "6d04ba0ea1eeba209147731840f9c2c1",
"sha256": "7ebef3ed95dfd83833c5663f5ce5dc2a2d2ef26e6e0038d91b048d49897d1c6d"
},
"downloads": -1,
"filename": "flask-appconfig-current-0.13.2.tar.gz",
"has_sig": false,
"md5_digest": "6d04ba0ea1eeba209147731840f9c2c1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17392,
"upload_time": "2023-09-24T21:40:46",
"upload_time_iso_8601": "2023-09-24T21:40:46.343464Z",
"url": "https://files.pythonhosted.org/packages/0d/e2/bf703cc343b560f81d814b3b3a514e6cf8a81dd54ce030945789e53c52cb/flask-appconfig-current-0.13.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-24 21:40:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mbr",
"github_project": "flask-appconfig",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "flask-appconfig-current"
}