How to deploy FlexMeasures

Here you can learn how to get FlexMeasures onto a server.


FlexMeasures can be deployed via Docker, where the solver is already installed and there are cloud infrastructures like Kubernetes you’d use. Read more at Running via Docker. You need other components (e.g. postgres and redis) which are not handled here. See Running a complete stack with docker-compose for inspiration.

WSGI configuration

On your own computer, flexmeasures run is a nice way to start FlexMeasures. On a production web server, you want it done the WSGI way.

Here, you’d want to hand FlexMeasures’ app object to a WSGI process, as your platform of choice describes. Often, that requires a WSGI script. Below is a minimal example.

# use this if you run from source, not needed if you pip-installed FlexMeasures
project_home = u'/path/to/your/code/flexmeasures'
if project_home not in sys.path:
   sys.path = [project_home] + sys.path

# create flask app - the name "application" has to be passed to the WSGI server
from import create as create_app
application = create_app()

The web server is told about the WSGI script, but also about the object that represents the application. For instance, if this script is called, then the relevant argument to the gunicorn server is wsgi:application.

A more nuanced one from our practice is this:

# This file contains the WSGI configuration required to serve up your
# web application.
# It works by setting the variable 'application' to a WSGI handler of some description.
# The crucial part are the last two lines. We add some ideas for possible other logic.

import os
project_home = u'/path/to/your/code/flexmeasures'
# use this if you want to load your own ``.env`` file.
from dotenv import load_dotenv
load_dotenv(os.path.join(project_home, '.env'))
# use this if you run from source
if project_home not in sys.path:
   sys.path = [project_home] + sys.path
# adapt PATH to find our LP solver if it is installed from source
os.environ["PATH"] = os.environ.get("PATH") + ":/home/seita/Cbc-2.9/bin"

# create flask app - the name "application" has to be passed to the WSGI server
from import create as create_app
application = create_app()

Keep in mind that FlexMeasures is based on Flask, so almost all knowledge on the web on how to deploy a Flask app also helps with deploying FlexMeasures.

Install the linear solver on the server

To compute schedules, FlexMeasures uses the HiGHS mixed integer linear optimization solver (FlexMeasures solver by default) or Cbc. Solvers are used through Pyomo, so in principle supporting a different solver would be possible.

You tell FlexMeasures with the config setting FLEXMEASURES_LP_SOLVER which solver to use.

However, the solver also needs to be installed - in addition to FlexMeasures (the Docker image already has it). Here is advice on how to install the two solvers we test internally:


We default to HiGHS, as it seems more powerful

HiGHS can be installed using pip:

$ pip install highspy

More information on the HiGHS website.

Cbc needs to be present on the server where FlexMeasures runs, under the cbc command.

You can install it on Debian like this:

$ apt-get install coinor-cbc

(also available in different popular package managers).

More information is on the CBC website.

If you can’t use the package manager on your host, the solver has to be installed from source. We provide an example script in ci/ to do that, where you can also pass a directory for the installation.

In case you want to install a later version, adapt the version in the script.