Skip to content

Configuration

Configuration: built-in defaults deep-merged with a user TOML file.

api_key(section)

Read the API key named by a section's api_key_env.

Parameters:

Name Type Description Default
section dict[str, Any]

A config section such as engines.openai.

required

Returns:

Type Description
str | None

The key, or None if no variable is configured or set.

Source code in src/murmurvault/config.py
161
162
163
164
165
166
167
168
169
170
171
def api_key(section: dict[str, Any]) -> str | None:
    """Read the API key named by a section's ``api_key_env``.

    Args:
        section: A config section such as ``engines.openai``.

    Returns:
        The key, or None if no variable is configured or set.
    """
    env = section.get("api_key_env") or ""
    return os.environ.get(env) if env else None

config_path()

Locate the user config file.

Returns:

Type Description
Path

$MURMURVAULT_CONFIG if set, else config.toml in the platform config directory.

Source code in src/murmurvault/config.py
119
120
121
122
123
124
125
126
def config_path() -> Path:
    """Locate the user config file.

    Returns:
        ``$MURMURVAULT_CONFIG`` if set, else ``config.toml`` in the platform config directory.
    """
    env = os.environ.get("MURMURVAULT_CONFIG")
    return Path(env).expanduser() if env else platformdirs.user_config_path(APP) / "config.toml"

load(path=None)

Load the effective configuration: built-in defaults deep-merged with the user file.

$MURMURVAULT_VAULT overrides the vault location.

Parameters:

Name Type Description Default
path Path | None

Config file to read; defaults to :func:config_path.

None

Returns:

Type Description
dict[str, Any]

The configuration.

Source code in src/murmurvault/config.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def load(path: Path | None = None) -> dict[str, Any]:
    """Load the effective configuration: built-in defaults deep-merged with the user file.

    ``$MURMURVAULT_VAULT`` overrides the vault location.

    Args:
        path: Config file to read; defaults to :func:`config_path`.

    Returns:
        The configuration.
    """
    path = path or config_path()
    cfg = copy.deepcopy(DEFAULTS)
    if path.exists():
        with path.open("rb") as fh:
            cfg = _merge(cfg, tomllib.load(fh))
    if env_vault := os.environ.get("MURMURVAULT_VAULT"):
        cfg["vault"] = env_vault
    cfg["vault"] = str(Path(cfg["vault"]).expanduser())
    return cfg