Wrapper for os.getenv that achieves return values of a specified type
Project description
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.
Usage
Install:
$ 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)
'true'
>>> getenv('BOOLEAN', type=bool)
True
>>> 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 tests.py
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
smart-getenv-1.1.0.tar.gz
(5.9 kB
view details)
File details
Details for the file smart-getenv-1.1.0.tar.gz
.
File metadata
- Download URL: smart-getenv-1.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e23c0451c2aef3982137f646aebde2fb67f6b106bc57343bf58d615d663eae9 |
|
MD5 | dcf09acf5f87575eeeeb56d993eec1ca |
|
BLAKE2b-256 | 0e9808b7e39638e6ee1da27f5b70f8b6453156b812a289356fd3dbbb807227bc |