Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Easily set Flask settings from environment variables

Project Description

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_')

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_'
Release History

Release History

This version
History Node

1.0.1

History Node

1.0.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Flask-Env-1.0.1.tar.gz (4.4 kB) Copy SHA256 Checksum SHA256 Source Aug 7, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting