Layer for Flask API's
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This layer allows configuration for Flask applications, with or without gunicorn and nginx deployment.


Include this layer in yourlayer.yaml


The Flask layer allows you to install dependencies for the Flask application via wheelhouse or via a requirements.txt file.


from charms.layer.flaskhelpers import install_dependencies, install_requirements

def install():
	#Install dependencies via wheelhouse
    install_dependencies(project_path + "/wheelhouse", project_path + "/requirements.txt")
    #Download dependencies via requirements.txt
    install_requirements(project_path + "/requirements.txt")

The flask layer will set the flask.installed state when installed and can be used as an indicator to start the Flask application. The state flask.nginx.installed is set once flask and nginx are installed. The start_api() function is used to tell the flask layer to launch the application. it takes three arguments: start_api(PATH_TO_PROJECT_MAIN_FILE, APP_OBJECT_NAME, FLASK_PORT). The APP_OBJECT_NAME is nothing more than the name you gave your app object in your application app = Flask(__name__).


def start_app():
   start_api(project_path + "/", "app", config["flask-port"])

Run Flask from

This mode is intended for development purposes. To run in this mode, deploy your charm with configuration option nginx: False. The API will be running on port 5000.

Run Flask with Gunicorn and NGINX

To run in this mode, deploy your charm with configuration option nginx: True. The Flask layer utilizes layer:nginx Repo and therefor requires a site.toml file for additional configuration.

The site.toml needs at least one configuration parameter:

"server_name" = "_"

The API will be running on the port specified by the config port.

The Flask api is run via systemd. To customize the generated unitfile, create a seperate unitfile template and a unitfile.toml and with additional configurations. For example, adding environment variables:

'env1' = 'Environment="VAR=example"'

Then call the start_api with the customized untifile template:

start_api(project_path + "/", "app", config["flask-port"], 'my.unitfile')


This software was created in the IBCN research group of Ghent University in Belgium. This software is used in Tengu, a project that aims to make experimenting with data frameworks and tools as easy as possible.