src.eddie.config

Collection of utils that are used for system and environment configuration.

Attributes

cwd

Classes

EnvVariable

Encapsulates all environment variable fetching, ensuring proper defaults and types.

Functions

_get_env_variable_func(→ str)

Read a string environment variable, with settings to allow defaults, empty values.

_get_bool_env_variable_func(→ bool)

Read an environment variable and attempts to cast to bool, with settings to allow defaults.

cast_str_to_bool(→ bool)

Attempt to cast a str to bool.

Module Contents

src.eddie.config.cwd
src.eddie.config._get_env_variable_func(var_name: str, default: str | None = None, allow_empty: bool = False) str

Read a string environment variable, with settings to allow defaults, empty values. To read a boolean use _get_bool_env_variable.

For public use please use EnvVariable. This module-level function is used by EnvVariable and children, but has been separated to simplify their usage.

Parameters:
  • var_name (str) – The name of the environment variable to retrieve.

  • default (Optional[str] = None) – Default return value if the environment variable is empty or does not exist.

  • allow_empty (bool) – If False then a KeyError will be raised if the environment variable is empty.

Returns:

The environment variable, or default if it is empty or does not exist.

Return type:

str

Raises:

KeyError – If allow_empty is False and the environment variable is empty string or None

src.eddie.config._get_bool_env_variable_func(var_name: str, default: bool | None = None) bool

Read an environment variable and attempts to cast to bool, with settings to allow defaults. For bool casting we have the problem where bool(“False”) == True but this function fixes that so get_bool_env_variable(“False”) == False

For public use please use EnvVariable. This module-level function is used by EnvVariable and children, but has been separated to simplify their usage.

Parameters:
  • var_name (str) – The name of the environment variable to retrieve.

  • default (Optional[bool] = None) – Default return value if the environment variable does not exist.

Returns:

The environment variable, or default if it does not exist

Return type:

bool

Raises:

ValueError – If allow_empty is False and the environment variable is empty string or None

src.eddie.config.cast_str_to_bool(string: str) bool

Attempt to cast a str to bool. For bool casting we have the problem where bool(“False”) == True but this function fixes that so cast_str_to_bool(“False”) == False

Parameters:

string (str) – The string to be cast to bool.

Returns:

The interpreted value of the string.

Return type:

bool

Raises:

ValueError – If the string cannot be cast to bool.

class src.eddie.config.EnvVariable

Encapsulates all environment variable fetching, ensuring proper defaults and types.

static _get_env_variable(var_name: str, default: str | None = None, allow_empty: bool = False) str

Read a string environment variable, with settings to allow defaults, empty values. To read a boolean use _get_bool_env_variable.

For public use please use EnvVariable.

Parameters:
  • var_name (str) – The name of the environment variable to retrieve.

  • default (Optional[str] = None) – Default return value if the environment variable is empty or does not exist.

  • allow_empty (bool) – If False then a KeyError will be raised if the environment variable is empty.

Returns:

The environment variable, or default if it is empty or does not exist.

Return type:

str

Raises:

KeyError – If allow_empty is False and the environment variable is empty string or None

static _get_bool_env_variable(var_name: str, default: bool | None = None) bool

Read an environment variable and attempts to cast to bool, with settings to allow defaults. For bool casting we have the problem where bool(“False”) == True but this function fixes that so get_bool_env_variable(“False”) == False

For public use please use EnvVariable.

Parameters:
  • var_name (str) – The name of the environment variable to retrieve.

  • default (Optional[bool] = None) – Default return value if the environment variable does not exist.

Returns:

The environment variable, or default if it does not exist

Return type:

bool

Raises:

ValueError – If allow_empty is False and the environment variable is empty string or None

STATSNZ_API_KEY
LINZ_API_KEY
MFE_API_KEY
DATA_DIR_GEOSERVER
POSTGRES_HOST
POSTGRES_PORT
POSTGRES_INTERNAL_HOST = 'db_postgres'
POSTGRES_INTERNAL_PORT
POSTGRES_DB
POSTGRES_USER
POSTGRES_PASSWORD
MESSAGE_BROKER_HOST
GEOSERVER_HOST
GEOSERVER_PORT
GEOSERVER_INTERNAL_HOST
GEOSERVER_INTERNAL_PORT
GEOSERVER_ADMIN_NAME
GEOSERVER_ADMIN_PASSWORD
IS_ON_GITHUB_ACTIONS = True