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.

  • 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.

  • 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.

Configure warnings by routing warnings to the logging system.

It also unhides DeprecationWarning.


Load the application.

Assembles the application by use of PACKAGES and EXTENSIONS configuration variables.

  1. Load extensions by calling setup_app() in module defined in EXTENSIONS.
  2. Register blueprints from each module defined in PACAKGES by looking searching in views.py for a blueprint or blueprints variable.
Parameters:app – Flask application.
flask_appfactory.app.load_config(app, module_name, **kwargs_config)[source]

Load configuration.

Configuration is loaded in the following order:

  1. Configuration module (i.e. module_name).
  2. Instance configuration in <instance folder>/<app name>.cfg
  3. Keyword configuration arguments.
  4. 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.

  • app – Flask application.
  • module_name – Configuration module.
  • kwargs_config – Configuration keyword arguments

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 module cli in each package. The variable must be a list of commands/groups to register, e.g:

import click

def testcmd():

commands = [testcmd, ]
  • cli – A click.Command or click.Group object.
  • app – Flask application.

Register modules with CLI variable.

flask_appfactory.cli.clifactory(create_app, **config)[source]

Create a click CLI application based on configuration.

The CLI will install the default run and shell commands from Flask, and load commands from the list of modules defined in PACKAGES. It will search in cli.py in each module for a variable cli.

The Flask application is not fully loaded unless the Flask app context is required.

Parameters:create_app – Flask application factory function.
flask_appfactory.cli.load_cli(app, cli=None)[source]

Load CLI commands and register them on CLI application.

  • app – Flask application instance.
  • cli – Click command group. If no group is provided, the commands are registered on the Flask applications cli.

Celery factory


Extensions for Flask-AppFactory.


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.


Dummy function for Flask 1.0.


Initialize Jinja2 loader and extensions.