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', **kwargs)[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.
-
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.