Skip to content

Environment variable definition with type

Notifications You must be signed in to change notification settings

reorx/getenv

Repository files navigation

getenv

Environment variable definition with type.

Install

pip install getenv

Usage

See example.py:

fromgetenvimportEnvapp_name='FOO'# Set the prefix for env varsEnv.set_prefix(app_name) # Define your envsENV_PROCESSES=Env('{prefix}_PROCESSES', type=int, default=1) ENV_DEBUG=Env('{prefix}_DEBUG', type=bool, default=False) ENV_OPERATOR=Env('{prefix}_OPERATOR', default=None) defmain(): processes=ENV_PROCESSES.get() debug=ENV_DEBUG.get() operator=ENV_OPERATOR.get() print('Run{} processes, debug ={}, operator ={}'.format(processes, debug, operator))

Run example.py normally:

$ FOO_PROCESSES=3 python example.py Run 3 processes, debug = False, operator = None

Then with envs:

$ FOO_PROCESSES=3 FOO_DEBUG=true FOO_OPERATOR=$(whoami) python example.py Run 3 processes, debug = True, operator = reorx

About

Environment variable definition with type

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published