Skip to main content

Environment variable definition with type

Project description

getenv

Environment variable definition with type.

Install

pip install getenv

Usage

See example.py:

from getenv import Env


app_name = 'FOO'

# Set the prefix for env vars
Env.set_prefix(app_name)

# Define your envs
ENV_PROCESSES = Env('{prefix}_PROCESSES', type=int, default=1)
ENV_DEBUG = Env('{prefix}_DEBUG', type=bool, default=False)
ENV_OPERATOR = Env('{prefix}_OPERATOR', default=None)


def main():
    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

Project details


Download files

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

Files for getenv, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size getenv-0.2.0-py3-none-any.whl (2.6 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page