Envs is a Python library (v1.4) designed for easy and typed access to environment variables. It automatically handles the parsing of environment variable values into various Python types, including strings, booleans, lists, tuples, integers, floats, and dictionaries. The library was last released in December 2021, suggesting a low-to-moderate release cadence, with updates as needed.
pip install envsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates both direct access to environment variables using `env()` and defining a structured settings class with type hints by inheriting from `envs.Env`. It showcases how `envs` automatically casts values to the specified Python types and provides default values for missing variables.
Always pass the default value directly to the `env()` callable. The library handles the instantiation correctly. If building custom wrappers, use `default_factory` or `None` with a check.
Ensure environment variable values for non-string types adhere to standard Python literal representations (e.g., 'true' or 'false' for booleans, '[item1, item2]' for lists, '{"key":"value"}' for dicts). For lists and tuples, comma-separated values are expected, and for dicts, a valid JSON string is required.Upgrade to the latest stable version of the `envs` library (`pip install --upgrade envs`) to benefit from improved type handling and the current API.
Always provide a default value (e.g., `env('VAR', 'default_value')`) or explicitly catch `KeyError` if the absence of a variable is an expected scenario. For required variables without a sensible default, letting `KeyError` propagate is often the correct behavior.Install the library using pip: `pip install envs`
Set the environment variable 'YOUR_ENV_VAR_NAME' in your operating system's environment, or provide a default value when accessing it, e.g., `env('YOUR_ENV_VAR_NAME', default='some_default')`.Ensure the environment variable's value matches the expected type. For example, if expecting an integer, the variable should contain a string that can be safely converted to an integer: `MY_INT_VAR=123` instead of `MY_INT_VAR=abc`.
No dependency data recorded yet.