A module for reading and writing environment variables.
Project description
A module for reading configuration values from the OS environment variables.
Compared to using straight os.getenv() this module provides convenience functions, for parsing basic datatypes. It also allows to specify optional default values if the environment variable does not exist. Basic environment variable parsing and sanitizing is also performed.
Usage
import os
import envitro
# fails when environment variables are missing
bool_required = envitro.bool("BOOL_ENV")
int_required = envitro.int("INTEGER_ENV")
str_required = envitro.str("STRING_ENV")
# basic sanitizing
os.environ["STR_ENV"] = " var with spaces "
envitro.str("STR_ENV") # returns "var with spaces"
# falls back to defaults
bool_default = envitro.bool("BOOL_NOT_FOUND", False)
int_default = envitro.int("INTEGER_NOT_FOUND", 42)
str_default = envitro.str("STRING_NOT_FOUND", "my_default")
# get and set raw environment variables
envitro.set("EXISTING_VAR", None) # clear the environment variable
envitro.set("RAW_STRING", " raw_string ")
envitro.get("RAW_STRING") # returns " raw_string "
envitro.get("MISSING_RAW_STRING", " defaultval ") # returns " defaultval "
# utility functions
envitro.isset("MAYBE_SET_VARIABLE") # return True/False
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
envitro-0.2.1.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for envitro-0.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca8824dc7dbd6b0f42a764ec94751078a758ef61a14d8189d76a8f7a0090c29a |
|
MD5 | 972656479ff57904fbccc005bdf7a656 |
|
BLAKE2b-256 | 523ffafa2d6e29fcf57a47302f29a598bf7f13cc4369de8a3853159deaeb11ce |