API Reference

evarify.ConfigStore

class evarify.ConfigStore(evar_defs)[source]

This is the container for your EnvironmentVariable definitions, along with their eventual loaded config values. Once load_values() is ran on an instance of this class, the config values are addressable via the Python dict API.

__init__(evar_defs)[source]
Parameters:evar_defs (dict) – Pass in a dict whose keys are config names and the values are EnvironmentVariable instances.
__weakref__

list of weak references to the object (if defined)

load_values()[source]

Go through the env var map, transferring the values to this object as attributes.

Raises:RuntimeError if a required env var isn’t defined.

evarify.EnvironmentVariable

class evarify.EnvironmentVariable(name, is_required=True, default_val=None, filters=None, help_txt=None)[source]

Defines an Environment Variable to handle.

__init__(name, is_required=True, default_val=None, filters=None, help_txt=None)[source]
Parameters:
  • name (str) – The name of the environment variable. This is case-sensitive!
  • is_required (bool) – If True, this variable must be defined when your Python process starts. If False, the default loaded value will match default_val.
  • default_val – If is_required is False and this environment variable is not defined, this value will be loaded.
  • filters (list) – A list of functions to pass the environment variable’s value (or default value) through. Order is significant!
  • help_txt (str) – Optional help text describing the environment variable.
__weakref__

list of weak references to the object (if defined)

evarify.filters.python_basics

evarify.filters.python_basics.comma_separated_str_to_list(config_val, evar)[source]

Splits a comma-separated environment variable into a list of strings.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Return type:

list

Returns:

The equivalent list for a comma-separated string.

evarify.filters.python_basics.comma_separated_to_set(config_val, evar)[source]

Splits a comma-separated environment variable into a set of strings.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Return type:

set

Returns:

The equivalent set for a comma-separated string.

evarify.filters.python_basics.validate_is_boolean_true(config_val, evar)[source]

Make sure the value evaluates to boolean True.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Raises:

ValueError if the config value evaluates to boolean False.

evarify.filters.python_basics.validate_is_not_none(config_val, evar)[source]

If the value is None, fail validation.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Raises:

ValueError if the config value is None.

evarify.filters.python_basics.value_to_bool(config_val, evar)[source]

Massages the ‘true’ and ‘false’ strings to bool equivalents.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Return type:

bool

Returns:

True or False, depending on the value.

evarify.filters.python_basics.value_to_int(config_val, evar)[source]

Convert the value to int.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Return type:

int

evarify.filters.python_basics.value_to_none(config_val, evar)[source]

Given a value that evaluates to a boolean False, return None.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Return type:

str or None

Returns:

Either the non-False value or None.

evarify.filters.python_basics.value_to_python_log_level(config_val, evar)[source]

Convert an evar value into a Python logging level constant.

Parameters:
  • config_val (str) – The env var value.
  • evar (EnvironmentVariable) – The EVar object we are validating a value for.
Returns:

A validated string.

Raises:

ValueError if the log level is invalid.