Read environment variables with EnvProxy¶
EnvProxy exposes seven typed getters. Each accepts a key, an optional
default, and returns a value converted to the target type. If the key is
missing and no default is given, EnvKeyMissingError is raised
(Exceptions reference).
The prefix (plus the uppercase and underscored toggles) controls
how key names are transformed into env-var names — see
Key transformations.
get_any¶
Retrieve the raw str value, untouched.
get_bool¶
Case-insensitive parsing of the strings:
| Truthy | Falsy |
|---|---|
yes |
no |
true |
false |
1 |
0 |
on |
off |
enable / enabled |
disable / disabled |
allow |
disallow / deny |
Any other value raises EnvValueError.
get_str¶
get_int¶
get_float¶
get_list¶
Splits on a separator (default ,) and strips whitespace by default.
# export MYAPP_ITEMS="a,b,c ,d"
items = proxy.get_list("items") # ["a", "b", "c", "d"]
items = proxy.get_list("items", separator=";") # custom separator
items = proxy.get_list("items", strip=False) # preserve whitespace
get_json¶
Parses the value as JSON via json.loads.
json.JSONDecodeError is propagated as-is.
Defaults¶
Every getter accepts a default. If the variable is missing, the default is returned without any type conversion: