Skip to content

EnvSource

A ConfigSource that loads values from environment variables.

Parameters:

Name Type Description Default
prefix str

a prefix for all environment variables that should be loaded (e.g. "APP_"). Only vars which begin with the prefix will be loaded.

required
separator str

a string that will separate nested values. Defaults to .

required

Note

All keys will be converted to lower case with the prefix stripped.

items(self)

Returns a generator for getting all key, value pairs

Source code in flex_config\env_source.py
52
53
54
def items(self) -> Iterable[Tuple[str, Any]]:
    """ Returns a generator for getting all key, value pairs """
    return self.to_dict().items()

to_dict(self)

Returns a generator for getting all key, value pairs

Source code in flex_config\env_source.py
40
41
42
43
44
45
46
47
48
49
50
def to_dict(self) -> Dict[str, Any]:
    """ Returns a generator for getting all key, value pairs """
    param_dict: Dict[str, Any] = {}
    for key, value in os.environ.items():
        if not key.startswith(self.prefix):
            continue
        key = key.replace(self.prefix, "")
        param_dict = insert_value_at_nested_key(
            dest_dict=param_dict, subkey_path=key.split(self.separator), value=value
        )
    return param_dict