penvΒΆ

pconfigs.penv(_cls=None, *, convention=None)[source]ΒΆ

Decorator that creates a config that accesses environment variables.

See also

For examples, see Environments

The decorator can be used with or without arguments:

  • @penv or @penv(): Use the attribute name as the environment variable name.

  • @penv(convention="uppercase"): Convert attribute names to uppercase when deriving environment variable names (for example, my_flag β†’ MY_FLAG).

  • @penv(convention=callable): Use a custom callable convention(name: str) -> str to transform attribute names into environment variable names.

Parameters:

convention (Convention | ConventionTransform, optional) – Name transformation strategy for environment variable names. May be the string "uppercase" or a callable (str) -> str. If omitted, attribute names are used as is.

Returns:

A new class derived from EnvironmentBase and using EnvironmentMetaclass, with annotated attributes replaced by EnvVar descriptors.

Return type:

Type

Raises:

ValueError – If an unsupported string convention is provided.