API Reference

Class definitions

class environment_variables.classes.EnvVarMeta(name, bases, dictionary)

Metaclass for creating EnvVars classes. Environment variable classes can be created by using this metaclass, but the recommended way is to use the @environment_variables wrapper.

class environment_variables.classes.EnvVars

Base class using the EnvVarMeta metaclass. Subclassing this class is equivalent to wrapping the class with the environment_variables function.

classmethod validate()

Run through all environment variables set in this class and make sure that they are all either defined on a system level, or have a default set. Also check that the variables are castable to the desired type.

Raises

EnvironmentValidationError – if any variable fails the

validation criteria. The error contains information on all the attributes that have failed the validation

environment_variables.classes.environment_variables(cls=None, *, validate=False, collect_prefixes=None)

Create an EnvVar class from the provided cls. This function can be used to wrap a class:

@environment_variables
class Environment:
    MY_VARIABLE: str

or:

@environment_variables(validate=True, collect_prefixes=['ZSH'])
class Environment:
    pass
Parameters
  • cls – the class definition to use

  • validate – if True, run through all environment variables

and raise an error if any variable is not set nor have a default :param collect_prefixes: if a list of prefixes is provided, the class will automatically add environment variables with those prefixes. This might be useful to get a quick access when debugging or experimenting, but it will dynamically add different environment variables depending on how the system is set up, while also obscuring what variables are being used, and is not recommended in a project where code is shared between several developers.

Type annotations