vibe.config.loader

Configuration file loading and processing for VIBE.

Handles YAML config file loading, validation, and session key management.

env

env(var_name: str, default: str = '') -> str

Environment variable function for use in configuration templates.

Parameters:
  • var_name (str) –

    Name of the environment variable

  • default (str, default: '' ) –

    Default value if variable is not set (defaults to empty string)

Returns:
  • str

    The environment variable value or default (empty string if not specified)

secret

secret(name: str, default: str = '') -> str

Read a secret from /run/secrets/ (Docker), falling back to env var.

Parameters:
  • name (str) –

    Secret name. Looked up as /run/secrets/, then os.environ[name].

  • default (str, default: '' ) –

    Value returned when neither source provides the secret.

Returns:
  • str

    The secret value, stripped of leading/trailing whitespace.

process_config_templates

process_config_templates(config: dict[str, Any]) -> dict[str, Any]

Process Jinja2 templates in configuration values.

This function recursively processes the configuration dictionary and renders any Jinja2 templates found in string values. It makes the env() function available for accessing environment variables.

Parameters:
  • config (dict) –

    Configuration dictionary to process

Returns:
  • dict( dict[str, Any] ) –

    Configuration with templates rendered

Raises:
  • TemplateSyntaxError

    If template syntax is invalid

  • KeyError

    If required environment variable is missing

load_configuration

load_configuration(config_file: str = 'config.yml', is_testing: bool = False) -> dict[str, Any]

Load and validate configuration from YAML file.

Parameters:
  • config_file (str, default: 'config.yml' ) –

    Path to the configuration file

  • is_testing (bool, default: False ) –

    Whether running in test mode

Returns:
  • dict( dict[str, Any] ) –

    Loaded configuration dictionary

Raises:
  • FileNotFoundError

    If config file not found in non-test mode

  • YAMLError

    If YAML parsing fails

  • ValueError

    If config file is not a valid mapping

ensure_session_key

ensure_session_key(config: dict[str, Any], config_file: str = 'config.yml', is_testing: bool = False) -> dict[str, Any]

Ensure a session storage key exists in the configuration.

If the key doesn't exist, generates a new one and saves it to the config file (unless in testing mode).

Parameters:
  • config (dict) –

    Configuration dictionary to modify

  • config_file (str, default: 'config.yml' ) –

    Path to the configuration file

  • is_testing (bool, default: False ) –

    Whether running in test mode

Returns:
  • dict( dict[str, Any] ) –

    Updated configuration with session key

normalize_config_keys

normalize_config_keys(config: dict[str, Any]) -> dict[str, Any]

Convert configuration keys to uppercase for Flask app.config compatibility.

Parameters:
  • config (dict) –

    Configuration dictionary

Returns:
  • dict( dict[str, Any] ) –

    Configuration with uppercase keys

apply_config_defaults

apply_config_defaults(config: dict[str, Any]) -> dict[str, Any]

Apply default values for essential configuration keys.

Parameters:
  • config (dict) –

    Configuration dictionary to modify

Returns:
  • dict( dict[str, Any] ) –

    Configuration with defaults applied

Raises:
  • ValueError

    If SECRET_KEY is missing in production