{"id":8137,"library":"envparse","title":"Envparse: Simple Environment Variable Parsing","description":"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.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/rconradharris/envparse","tags":["environment variables","configuration","12-factor app","dotenv"],"install":[{"cmd":"pip install envparse","lang":"bash","label":"Install stable version"},{"cmd":"pip install git+https://github.com/rconradharris/envparse.git","lang":"bash","label":"Install from GitHub (potentially newer changes)"}],"dependencies":[],"imports":[{"symbol":"env","correct":"from envparse import env"},{"symbol":"Env","correct":"from envparse import Env"}],"quickstart":{"code":"import os\nfrom envparse import env, Env\n\n# Create a dummy .env file for demonstration\nwith open('.env', 'w') as f:\n    f.write('DATABASE_URL=sqlite:///db.sqlite\n')\n    f.write('DEBUG=True\n')\n    f.write('ALLOWED_HOSTS=localhost,127.0.0.1\n')\n    f.write('WORKERS=4\n')\n\n# Load .env file (optional, envparse searches parent directories too)\nenv.read_envfile()\n\n# --- Standard usage (env object) ---\n\ndb_url = env('DATABASE_URL', default='postgres://localhost/mydb')\ndebug_mode = env('DEBUG', type=bool, default=False)\nworkers = env.int('WORKERS', default=2) # Implicit type casting for built-in types\n\nprint(f\"[Standard] DB URL: {db_url}\")\nprint(f\"[Standard] Debug Mode: {debug_mode} (type: {type(debug_mode)})\")\nprint(f\"[Standard] Workers: {workers} (type: {type(workers)})\")\n\n# --- Usage with schema (Env class) ---\n\n# Define a schema for environment variables\nconfig_schema = Env(\n    ALLOWED_HOSTS=(list, ['*']), # (type, default)\n    SECRET_KEY=str # type only, no default, will raise ConfigurationError if missing\n)\n\n# Load config from schema\nallowed_hosts = config_schema('ALLOWED_HOSTS')\n\nprint(f\"[Schema] Allowed Hosts: {allowed_hosts} (type: {type(allowed_hosts)})\")\n\n# Clean up dummy .env file\nos.remove('.env')\n","lang":"python","description":"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."},"warnings":[{"fix":"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()`.","message":"The `env.read_envfile()` method uses `os.environ.setdefault()`, which means environment variables already set in the operating system will *not* be overridden by values in the `.env` file. This can lead to unexpected behavior if you intend for the `.env` file to always be the source of truth.","severity":"gotcha","affected_versions":"0.1.x, 0.2.0"},{"fix":"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`.","message":"There is a discrepancy in keyword arguments for type casting between the PyPI 0.2.0 description (`type`, `subtype`) and the current GitHub README (`cast`, `subcast`). For the installed 0.2.0 version from PyPI, use `type=some_type` and `subtype=some_nested_type` (e.g., for lists). If installing directly from GitHub, `cast` and `subcast` might be required.","severity":"gotcha","affected_versions":"0.2.0 (PyPI install)"},{"fix":"Evaluate newer alternatives for active development. If continuing with `envparse`, be aware that issues might not be actively addressed.","message":"The `envparse` library, at version 0.2.0, has not seen a new release since December 2015. While functional, it may lack features or bug fixes present in more actively maintained environment variable parsing libraries. Consider alternatives like `python-decouple` or `environs` if active development and newer features are a priority.","severity":"deprecated","affected_versions":"0.2.0 (since 2015)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"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.","cause":"Attempting to access an environment variable that is not set, and no default value or schema is provided.","error":"KeyError: 'ENV_VAR_NAME'"},{"fix":"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`.","cause":"Boolean environment variables are parsed as strings ('True', 'False', '1', '0') by default. Without explicit casting, `env('DEBUG')` might return the string 'True' or '0', which evaluates to `True` in a boolean context, but `is True` will fail for the string 'True' and '0' is not `False`.","error":"assert mail_enabled is True # where MAIL_ENABLED=0 in .env"},{"fix":"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.","cause":"Attempting to use convenience methods like `env.json()` or `env.url()` which might not be available in older versions or are not explicitly imported.","error":"AttributeError: 'envparse.env.Env' object has no attribute 'json'"}]}