env_proxy.env_proxy¶
env_proxy ¶
EnvProxy creates a proxy to environmental variables with typehinting and type conversion.
EnvProxy ¶
A proxy to environmental variables with typehinting and type conversion.
Source code in env_proxy/env_proxy.py
get_any ¶
Get value from env typed as Any.
If default is not given and the key does not exist, ValueError is raised.
Source code in env_proxy/env_proxy.py
get_bool ¶
Get bool value from the environment.
Case-insensitive check for truthy and falsy strings is performed to determine the boolean value.
Truthy values: yes, true, 1, on, enable, enabled, allow Falsy values: no, false, 0, off, disable, disabled, deny
If default is not given and the key does not exist, ValueError is raised.
Source code in env_proxy/env_proxy.py
get_str ¶
Get str value from environment.
If default is not given and the key does not exist, ValueError is raised.
Source code in env_proxy/env_proxy.py
get_int ¶
Get value from the environment as int type. If default is not given and the key does not exist, ValueError is raised.
Source code in env_proxy/env_proxy.py
get_float ¶
Get value from the environment as float type.
If default is not given and the key does not exist, ValueError is raised.
Source code in env_proxy/env_proxy.py
get_list ¶
get_list(
key: str,
default: T | Sentinel = UNSET,
*,
separator: str = ",",
strip: bool = True,
) -> list[str] | T
Get a list of string values from the environment.
The list is expected to be separated by separator (defaults to comma ,).
List items are stripped of leading and trailing whitespace by default.
If default is not given and the key does not exist, ValueError is raised.
Source code in env_proxy/env_proxy.py
get_json ¶
Get a JSON value and parse it using :func:json.loads.
If the key is missing and no default is given, raises
:class:EnvKeyMissingError. If the value is present but is not
valid JSON, :class:json.JSONDecodeError (itself a
:class:ValueError subclass) is propagated unchanged — this is
the one documented deviation from env-proxy's
EnvProxyError-only contract. See
:mod:env_proxy.exceptions for details.
Source code in env_proxy/env_proxy.py
apply_env ¶
A context manager that temporarily sets the specified environment variables to the given values. When the context is exited, the original environment variables are restored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**env
|
str
|
Arbitrary keyword arguments where the key is the environment variable name and the value is the environment variable value to set. |
{}
|
Example
with apply_env(MY_VAR='value'): # MY_VAR is set to 'value' within this block ...