Skip to main content
https://badge.fury.io/py/Flask-Env.svg https://travis-ci.org/brettlangdon/flask-env.svg?branch=master

Easily set Flask settings from environment variables.

The reason for using flask-env is to be able to follow the 12-factor app suggestions for configuring your application.

With flask-env you can define your default configuration options in code and very easily override via environment variables.

Installation

pip install Flask-Env

Usage

With flask-env you will define your configuration as an object and load it into your Flask application via app.config.from_object method.

Python 2

from flask import Flask
from flask_env import MetaFlaskEnv


class Configuration(object):
    __metaclass__ = MetaFlaskEnv

    DEBUG = False
    PORT = 5000


app = Flask(__name__)
app.config.from_object(Configuration)

Python 3

from flask import Flask
from flask_env import MetaFlaskEnv


class Configuration(metaclass=MetaFlaskEnv):
    DEBUG = False
    PORT = 5000


app = Flask(__name__)
app.config.from_object(Configuration)

Overriding environment variables

# Export environment variable for shell session
export DEBUG=true

# Set explicitly for a specific command execution
PORT=8000 python app.py

Configuring flask-env

flask-env offers two configuration options to determine how/which environment variables are loaded.

ENV_PREFIX

Only consider environment variables that start with this prefix. The prefix will be removed from the environment variable name when setting in the configuration. (default: '', example: ENV_PREFIX = 'MYAPP_')

ENV_LOAD_ALL

Whether or not to load all environment variables for the configuration object. When False only settings predefined on the configuration object are loaded, all others are ignored. When True all environment variables defined in os.environ will get loaded into your configuration object. (default False)

Setting configuration values

You can set the flask-env configuration settings directly on your Flask configuration object.

from flask_env import MetaFlaskEnv


class Configuration(metaclass=MetaFlaskEnv):
    ENV_PREFIX = 'MYAPP_'
    ENV_LOAD_ALL = False

Release files for Flask-Env 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Env 2.0.0
File Size Uploaded
Flask-Env-2.0.0.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Env 2.0.0
File Interpreter ABI Platform
Flask_Env-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.1 kB

Release files / Flask-Env-2.0.0.tar.gz

Download URL Flask-Env-2.0.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e10ebc8ac8f5d4696f228be8ad528c697c701b706c754fc54c8a5aa784eb73f1
BLAKE2b-256 checksum
How to use checksums
92c42146ffb5dbbee8718e35dbcda74b416a6a986bf06e4f408a2ce751b6b248
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Flask_Env-2.0.0-py3-none-any.whl

Download URL Flask_Env-2.0.0-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6515b2cb2f62dc2743ba2600f4583147128f28a36cb73040a2ab12c54e329f67
BLAKE2b-256 checksum
How to use checksums
b20b64d974a7ae63d73401c3cb3288b5ede82493af03aae0d4b0a4dc40051e19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.1.0

2 release files

1.0.1

1 release file

1.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page