Skip to main content

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.

PyPi page

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?'

Project details


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.0.4.tar.gz (1.7 kB view details)

Uploaded Source

File details

Details for the file smart-getenv-1.0.4.tar.gz.

File metadata

File hashes

Hashes for smart-getenv-1.0.4.tar.gz
Algorithm Hash digest
SHA256 d05390b6ee96d72ab60d7f35eee2c13f65f152dbd70b2f791cd8845dd7ccbcf4
MD5 f3196f39115aaa645cab3f1fca2402f6
BLAKE2b-256 ec763acfada3296f804191c91227a7c9e13e8d0647f2e820a73d0712a98cb76f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page