{"id":27633,"library":"cattrs-env","title":"cattrs-env","description":"A Python library for parsing and validating environment variables using cattrs structured configuration. Version 1.0.4 supports Python >=3.7. Released under MIT license. Low release cadence.","status":"active","version":"1.0.4","language":"python","source_language":"en","source_url":"https://github.com/henryivesjones/cattrs-env","tags":["environment-variables","cattrs","validation","configuration"],"install":[{"cmd":"pip install cattrs-env","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for structured parsing/validation of env vars.","package":"cattrs","optional":false},{"reason":"Used to define data classes with cattrs.","package":"attrs","optional":false}],"imports":[{"note":"Incorrect class name; the correct class is EnvSettings.","wrong":"from cattrs_env import Settings","symbol":"EnvSettings","correct":"from cattrs_env import EnvSettings"}],"quickstart":{"code":"from attrs import define\nfrom cattrs_env import EnvSettings\n\n@define\nclass Config:\n    host: str = 'localhost'\n    port: int = 8080\n\nconfig = EnvSettings(Config).parse_env()\nprint(config.host, config.port)\n","lang":"python","description":"Define an attrs class and use EnvSettings to automatically populate fields from environment variables with matching names (e.g., HOST, PORT)."},"warnings":[{"fix":"Use the 'var_name' argument in the field metadata to override: host: str = field(metadata={'var_name': 'MY_HOST'})","message":"Environment variable names are uppercased by default. A field 'host' expects env var 'HOST'.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure env var values are valid Python literals (e.g., no extra whitespace, quotes for strings). Use the 'type' argument if you need explicit control.","message":"cattrs-env uses ast.literal_eval to parse string values (e.g., '8080' becomes int). If the string is not a valid Python literal, it falls back to str type without warning. This can silently misparse values like '8080 ' (with trailing space) as string.","severity":"gotcha","affected_versions":"*"},{"fix":"N/A","message":"No deprecations known.","severity":"deprecated","affected_versions":"N/A"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"pip install cattrs-env","cause":"Library not installed or installed with a different name (e.g., cattrs-env).","error":"ModuleNotFoundError: No module named 'cattrs_env'"},{"fix":"EnvSettings(Config) where Config is an attrs-decorated class.","cause":"Missing the attrs class argument when instantiating EnvSettings.","error":"TypeError: EnvSettings() takes exactly 1 argument (0 given)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}