Envparse is a Python utility designed for parsing environment variables, inspired by the 12 Factor App methodology. It simplifies configuration management by providing a wrapper around `os.environ` that handles type casting and default values, reducing boilerplate code. The current stable version on PyPI is 0.2.0, released in December 2015, indicating a mature but infrequently updated library.
pip install envparseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates both the standard `env` object and the schema-based `Env` class. It shows how to load variables, cast them to specific types (explicitly and implicitly for built-in types), and provide default values. A dummy `.env` file is created and cleaned up for a self-contained example. Note the use of `type` for explicit casting and `env.int()` for implicit casting of built-in types, as per version 0.2.0 documentation.
Manually delete conflicting environment variables before running your application, or consider a library that explicitly supports overriding existing variables. For testing, you might use `del os.environ['VAR_NAME']` before calling `read_envfile()`.
Refer to the specific version's documentation or the GitHub README for the most up-to-date API. For `pip install envparse==0.2.0`, use `type` and `subtype`.
Evaluate newer alternatives for active development. If continuing with `envparse`, be aware that issues might not be actively addressed.
Provide a default value: `value = env('ENV_VAR_NAME', default='fallback_value')`. Alternatively, use the `Env` class with a defined schema, which raises a `ConfigurationError` for missing variables, providing a more specific error.Always explicitly cast boolean-like environment variables: `mail_enabled = env('MAIL_ENABLED', type=bool)` or `mail_enabled = env.bool('MAIL_ENABLED')`. This will correctly convert '0', 'False', 'off' to `False` and '1', 'True', 'on' to `True`.For basic types, use explicit casting: `json_data = env('JSON_VAR', type=dict)`. Ensure you are using the correct method signatures as per the specific version of `envparse` being used, or consult the GitHub README for the most current API if these convenience methods are desired and not working.No dependency data recorded yet.