Flask Series: Application Configuration

Each application needs a configuration. Flask allows developers to implement their application configuration using several different approaches:

  • file-based;
  • object-based;
  • environment-variable-based;
  • instance-folders-based;

Regardless of what approach developer chooses for her/ his Flask application configuration, all configuration values are loaded on the config attribute(configuration dictionary) of the Flask application object:

There is a list of configuration values, used internally by Flask.

Note that Flask expects configuration to be available when the application starts up.

File-based configuration

Flask allows developers to store their configuration in separate files and load it from them.

The configuration file uses INI file syntax – name/value pairs in a plain text file, separated by an equal sign (“=”).

Object-based configuration

Good pattern to follow is to use classes for your Flask application configuration:

and to use this configuration, the from_object method should be used:


EnvVars-based configuration

The application can be configured based on configuration file, which is specified by a environment variable:

here the FLASK_CONFIG_FILE environment variable points to the configuration file.

Instance-based configuration

Since version 0.8 Flask provides one more configuration option – instance folders. The instance folder is designed not to be under source control and could store sensitive information. This instance folder should be directly deployed on the production server. To be able to use it, the instance_path of the Flask object should be specified:

or use it as relative path, where we have instance folder under our application folder.


Now you are ready to configure your application based on the instance folders mechanism, where the flask.cfg is stored either under the instance_path  (1) or under the instance folder (2)

Best Practice

Good practice is to have a default configuration, which is under source control and to override it with sensitive and specific information kept in instance folders. For the default configuration you could use object-based configuration hierarchy(described in Object-based configuration section) and to manage which configuration object to load via environment variables:

The complete demo application, described in this blog post, can be found here.

In the next blog post I will describe how to use templates in your Flask project.


  • damyanbogoev

    Thank you for noticing it. It is a typo in both the blog post and the code. I will fix it.

  • Diego Aguilera

    If I update a variable, will it update the config file?

  • damyanbogoev

    The configuration practice described in the blog post and implemented within the sample application (flask-bookshelf) suggests to use default configurations via object-based config sections and to override them with the instance-folders based approach, if it is in place.
    If you are following this approach – the instance-folders config (if it has one) will override a configuration key-value pair from the object-based one.