API Docs¶
Application factory¶
Flask application factory.
-
flask_appfactory.app.
appfactory
(app_name, module_name, load=True, **kwargs_config)[source]¶ Create a Flask application according to a defined configuration.
Parameters: - app_name – Flask application name.
- module_name – Python configuration module.
- load – Load application (instead of only the configuration).
Default:
True
. - kwargs_config – Extra configuration variables for the Flask application.
-
flask_appfactory.app.
base_app
(app_name, instance_path=None, static_folder=None, static_url_path=u'/static/', instance_relative_config=True, template_folder=u'templates', flask_cls=<class 'flask.app.Flask'>)[source]¶ Create a base Flask Application.
Ensures instance path and is set and created. Instance path defaults to
<sys.prefix>/var/<app name>-instance
.Additionally configure warnings to be routed to the Python logging system, and by default makes
DeprecationWarning
loud.Changed in version v0.2.0: Added
flask_cls
parameter.Parameters: - app_name – Flask application name.
- instance_path – Instance path
- static_folder – Static folder.
- static_url_path – URL path of static folder. Default:
/static/
. - instance_relative_config – Use instance relative config
Default:
True
. - template_folder – Template folder. Default:
templates
. - flask_cls – Flask Application class. Default:
Flask
.
-
flask_appfactory.app.
configure_warnings
()[source]¶ Configure warnings by routing warnings to the logging system.
It also unhides
DeprecationWarning
.
-
flask_appfactory.app.
load_application
(app)[source]¶ Load the application.
Assembles the application by use of
PACKAGES
andEXTENSIONS
configuration variables.- Load extensions by calling
setup_app()
in module defined inEXTENSIONS
. - Register blueprints from each module defined in
PACAKGES
by looking searching inviews.py
for ablueprint
orblueprints
variable.
Parameters: app – Flask application. - Load extensions by calling
-
flask_appfactory.app.
load_config
(app, module_name, **kwargs_config)[source]¶ Load configuration.
Configuration is loaded in the following order:
- Configuration module (i.e.
module_name
). - Instance configuration in
<instance folder>/<app name>.cfg
- Keyword configuration arguments.
- Environment variables specified in
<app name>_APP_CONFIG_ENVS
configuration variable or comma separated list in environment variable with the same name.
Additionally checks if
SECRET_KEY
is set in the configuration and warns if it is not.Parameters: - app – Flask application.
- module_name – Configuration module.
- kwargs_config – Configuration keyword arguments
- Configuration module (i.e.
CLI factory¶
Command line interface factory.
-
class
flask_appfactory.cli.
CLIDiscoveryRegistry
(cli, app, **kwargs)[source]¶ Discover CLI modules and register them on a command collection.
Searches for a variable
commands
in a modulecli
in each package. The variable must be a list of commands/groups to register, e.g:import click @click.command() def testcmd(): click.echo("Test") commands = [testcmd, ]
Parameters: - cli – A
click.Command
orclick.Group
object. - app – Flask application.
- cli – A
-
flask_appfactory.cli.
clifactory
(create_app, **config)[source]¶ Create a click CLI application based on configuration.
The CLI will install the default
run
andshell
commands from Flask, and load commands from the list of modules defined inPACKAGES
. It will search incli.py
in each module for a variablecli
.The Flask application is not fully loaded unless the Flask app context is required.
Parameters: create_app – Flask application factory function.
Celery factory¶
Celery application factory.
Extensions¶
Extensions for Flask-AppFactory.
Jinja2¶
Order-aware Jinja2 loader and extensions initialization.
The default Flask Jinja2 loader is not aware of the order defined in
PACKAGES
. This means that if two modules provides the same template, it is
undefined which template is being rendered. This extension adds a
PACKAGES
order-aware Jinja2 loader, which will search for a given template
in each module in the order defined by PACKAGES
. This allows modules to
override templates defined in modules later in PACKAGES
.
Additionally the extension will load any Jinja2 extension defined in the
JINJA2_EXTENSIONS
configuration variable.
-
class
flask_appfactory.ext.jinja2.
OrderAwareDispatchingJinjaLoader
(app)[source]¶ Order aware dispatching Jinja loader.
Customization of default Flask Jinja2 template loader. By default the Flask Jinja2 template loader is not aware of the order of Blueprints as defined by the
PACKAGES
configuration variable.