src.config

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

Classes

EnvVariable

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

Functions

_get_env_variable(→ str)

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

_get_bool_env_variable(→ 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.config._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

src.config._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

src.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.config.EnvVariable

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

STATSNZ_API_KEY
LINZ_API_KEY
MFE_API_KEY
NIWA_API_KEY
DEBUG_TRACEBACK = True
TEST_DATABASE_INTEGRATION = True
DATA_DIR
DATA_DIR_MODEL_OUTPUT
DATA_DIR_GEOSERVER
FLOOD_MODEL_DIR
POSTGRES_HOST
POSTGRES_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
_LIDAR_DIR
_DEM_DIR
_LAND_FILE
_INSTRUCTIONS_FILE