pip install py-envconfig
Set some environment variable, or write a .env
file.
HOST=localhost
PORT=6000
MY_APP_SERVICE=bookings
RELEASE_NUMBER=12
ENV=dev
Then specify your config:
from envconfig import param
from envconfig import EnvConfig
class AppConfig(EnvConfig):
"""App env config."""
HOST = param.Str(required=True)
PORT = param.Int(required=True)
PASSWORD = param.Str(override="SECRET_REDIS_PW", required=True)
SERVICE = param.Str(prefix="MY_APP_")
VERSION = param.Int(override="RELEASE_NUMBER")
ENV = param.Str(default="prod")
config = AppConfig()
# Access by class attribute or subscript
config.USER
config["USER"]
Setup flask config:
config = AppConfig()
app.config.from_object(config)
Point to a .env
file
config = AppConfig("./.env")
Some functionality provided by dotenv
-
Increase verbosity
AppConfig(verbose=True)
-
Override existing env vars with the env vars defined in
.env
.AppConfig(override=True)
To publish package and tag git:
make tag