GithubHelp home page GithubHelp logo

skehmatics / flask-env Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brettlangdon/flask-env

0.0 1.0 0.0 24 KB

Easily set Flask settings from environment variables

Home Page: https://pypi.python.org/pypi/Flask-Env

License: MIT License

Python 100.00%

flask-env's Introduction

Flask-Env

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

flask-env's People

Contributors

brettlangdon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.