Simple and lightweight environment variable ingestion
Project description
lightweight-environ
Simple and lightweight environment variable ingestion. No dependencies.
Designed for use with Django but it should be suitable for any Python 3 framework / project.
install
pip install lightweight-environ
usage
Given an environment:
MY_STRING=ford_prefect
MY_INTEGER=42
MY_FLOAT=6.283
MY_BOOLEAN=True
MY_LIST=DONT,PANIC
from lightweight_environ import Env
>>> Env.get('A_MISSING_VAR') # Raises a KeyError exception if 'MY_ENV_VAR' is not set
Traceback ...
>>> Env.get('A_MISSING_VAR', 'foo') # first optional arg is a default returned if 'MY_ENV_VAR' is not set
'foo'
>>> Env.get('MY_STRING') # get returns a string
'ford_prefect'
>>> Env.get('MY_INTEGER') # get returns a string
'42'
>>> Env.int('MY_INTEGER') # integer coersion
42
>>> Env.bool('MY_BOOLEAN') # boolean coersion
True
>>> Env.bool('A_MISSING_VAR') # Reading via bool does not raise an exception if the value is missing
False # It defaults to `False`
>>> Env.bool('A_MISSING_VAR', True) # All methods support a default for missing keys
True
>>> Env.float('MY_FLOAT') # float coersion
6.283
>>> Env.list('MY_LIST') # list coersion from a string of comma separated values
['DONT', 'PANIC']
>>> Env.list('A_MISSING_VALUE', 'Oh,freddled,gruntbuggly')
['Oh', 'freddled', 'gruntbuggly']
>>> Env.list('A_MISSING_VALUE', ['Oh', 'freddled', 'gruntbuggly'])
['Oh', 'freddled', 'gruntbuggly']
Env.has('A_MISSING_VALUE') # Test if a variable exists
False
Env.has('MY_INTEGER')
True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for lightweight-environ-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c9519bf98583b17e2315b64f962a8a62de69e02c550c8f2656a561f6b86e6f1 |
|
MD5 | 98cdef3bf038debc7ebe8c0c527df8ef |
|
BLAKE2b-256 | 3eed10dbeace689399b3b15e4243e7307a60cc4a2d7624f910d24692f61f6c01 |
Close
Hashes for lightweight_environ-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1713d019a3f3c307ffc4d99a4cc89a34ada4ec19599c279e37b7f224ebef63e |
|
MD5 | 9435eabf854d4ae639c9c07f6478338c |
|
BLAKE2b-256 | c9b7fc87822f6e43a65dc994af07535319e3e1d3e1b4176d45ad96f0a79558a8 |