Skip to main content

Python smart getenv

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

Run tests:

$ python tests.py

Metadata

Release files for smart-getenv 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smart-getenv 1.1.0
File Size Uploaded Provenance Actions
smart-getenv-1.1.0.tar.gz 5.9 kB Without provenance Details for smart-getenv-1.1.0.tar.gz

Release files / smart-getenv-1.1.0.tar.gz

Download URL smart-getenv-1.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8e23c0451c2aef3982137f646aebde2fb67f6b106bc57343bf58d615d663eae9
BLAKE2b-256 checksum
How to use checksums
0e9808b7e39638e6ee1da27f5b70f8b6453156b812a289356fd3dbbb807227bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for smart-getenv 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page