skip to navigation
skip to content

smart-getenv 1.1.0

Wrapper for os.getenv that achieves return values of a specified type

Since environment variables in os.environ are strings, it often appears inconvenient to store and retrieve other data types such as bool or list. The package provides a single function that wraps os.getenv and allows you to specify the desired variable type.

Tested and supported types: str, int, float, list. tuple, dict.

PyPi page



$ pip install smart-getenv

Prepare the variables:

$ export BOOLEAN=true
$ export LIST=a,b,c
$ export TRICKY_LIST=d:e:f
$ export DICT="{'foo':'bar'}"

Get them:

>>> from smart_getenv import getenv
>>> getenv('BOOLEAN', type=str)
>>> getenv('BOOLEAN', type=bool)
>>> getenv('LIST', type=list)
['a', 'b', 'c']
>>> getenv('LIST', type=tuple)
('a', 'b', 'c')
>>> getenv('TRICKY_LIST', type=list, separator=':')
['d', 'e', 'f']
>>> getenv('DICT', type=dict)
{'foo': 'bar'}
>>> getenv('LOST', default='default value anyone?')
'default value anyone?'

Run tests:

$ python
File Type Py Version Uploaded on Size
smart-getenv-1.1.0.tar.gz (md5) Source 2016-06-04 5KB