Registry / serialization / cattrs-env

cattrs-env

JSON →
library1.0.4pypypi✓ verified 85d ago

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.

pip install cattrs-env
INSTALL
IMPORT
SIG · CATTRS-ENV
C
cattrs-env
serializationpythonv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CattrsEnv
✓ from cattrs_env import CattrsEnv
✗ from cattrs_env import EnvSettings

Define an attrs class and use EnvSettings to automatically populate fields from environment variables with matching names (e.g., HOST, PORT).

from attrs import define from cattrs_env import EnvSettings @define class Config: host: str = 'localhost' port: int = 8080 config = EnvSettings(Config).parse_env() print(config.host, config.port)
Debug
Known issues
gotchaEnvironment variable names are uppercased by default. A field 'host' expects env var 'HOST'.
fix
Use the 'var_name' argument in the field metadata to override: host: str = field(metadata={'var_name': 'MY_HOST'})
affects: *
gotchacattrs-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.
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.
affects: *
deprecatedNo deprecations known.
fix
N/A
affects: N/A
Upgrade
Version history
1.0.4latest on PyPI · released Aug 25, 2023
Audit
Dependencies
cattrsrequiredRequired for structured parsing/validation of env vars.
attrsrequiredUsed to define data classes with cattrs.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
cattrs-env — pip install cattrs-env · libregistry