Classes
ConfigLoadError
5
▼
Raised when configuration loading fails.
This exception is raised for various configuration loadin…
ConfigLoadError
5
▼
Raised when configuration loading fails.
This exception is raised for various configuration loading failures
including missing directories, invalid YAML syntax, or file permission
errors. ExtendsBengalConfigErrorfor consistent
error handling throughout the configuration system.
Attributes
| Name | Type | Description |
|---|---|---|
message |
— |
Description of the error. |
file_path |
— |
Path to the problematic file or directory. |
line_number |
— |
Line number where the error occurred (if applicable). |
suggestion |
— |
Helpful suggestion for fixing the error. |
original_error |
— |
The underlying exception, if any. |
ConfigDirectoryLoader
7
▼
Load configuration from a directory structure with layered overrides.
This loader supports multi-f…
ConfigDirectoryLoader
7
▼
Load configuration from a directory structure with layered overrides.
This loader supports multi-file configurations organized in directories, with automatic environment detection and profile-based customization. It provides deterministic merging with clear precedence rules.
Features:
- Multi-file configs: Split configuration across multiple YAML files
in ``_default/`` for better organization. - Environment overrides: Automatic detection of deployment environment
with corresponding configuration overrides. - Profile support: User-defined profiles for different use cases
(e.g., ``--profile writer``). - Origin tracking: Optional tracking of which file contributed each
configuration key (for ``bengal config show --origin``). - Feature expansion: Simple feature toggles expanded to detailed config.
Attributes
| Name | Type | Description |
|---|---|---|
track_origins |
— |
Whether origin tracking is enabled. |
origin_tracker |
ConfigWithOrigin | None
|
The :class: |
Methods
load
3
dict[str, Any]
▼
Load config from directory with precedence.
Precedence (lowest to highest):
1.…
load
3
dict[str, Any]
▼
def load(self, config_dir: Path, environment: str | None = None, profile: str | None = None) -> dict[str, Any]
Load config from directory with precedence.
Precedence (lowest to highest):
- Bengal DEFAULTS from defaults.py (built-in defaults)
- config/_default/*.yaml (base user config)
- config/environments/
.yaml (environment overrides) - config/profiles/
.yaml (profile settings)
Parameters
| Name | Type | Description |
|---|---|---|
config_dir |
— |
Path to config directory |
environment |
— |
Environment name (auto-detected if None) Default:None
|
profile |
— |
Profile name (optional) Default:None
|
Returns
dict[str, Any]
Merged configuration dictionary
get_origin_tracker
0
ConfigWithOrigin | None
▼
Get the origin tracker instance.
Returns the origin tracker if tracking was en…
get_origin_tracker
0
ConfigWithOrigin | None
▼
def get_origin_tracker(self) -> ConfigWithOrigin | None
Get the origin tracker instance.
Returns the origin tracker if tracking was enabled during initialization
andload() has been called. The tracker contains information about
which configuration file contributed each key.
Returns
ConfigWithOrigin | None
The :class:`ConfigWithOrigin` instance if ``track_origins=True``
was passed to the constructor and config has been loaded,
otherwise ``None``.
Internal Methods 3 ▼
__init__
1
▼
Initialize the directory configuration loader.
__init__
1
▼
def __init__(self, track_origins: bool = False) -> None
Parameters
| Name | Type | Description |
|---|---|---|
track_origins |
— |
If False
|
_load_directory
2
dict[str, Any]
▼
Load and merge all YAML files in a directory.
Files are loaded in sorted order…
_load_directory
2
dict[str, Any]
▼
def _load_directory(self, directory: Path, _origin_prefix: str = '') -> dict[str, Any]
Load and merge all YAML files in a directory.
Files are loaded in sorted order (alphabetically) for deterministic behavior. All files are collected first, then merged in a single batch operation for O(K × D) complexity instead of O(F × K × D).
Parameters
| Name | Type | Description |
|---|---|---|
directory |
— |
Directory containing YAML files to load. |
_origin_prefix |
— |
Reserved for future origin tracking (currently unused). Default:''
|
Returns
dict[str, Any]
Merged configuration dictionary from all files in the directory.
_normalize_site_keys
1
dict[str, Any]
▼
Move common site keys placed at the root into the site section.
Provides backw…
_normalize_site_keys
1
dict[str, Any]
▼
def _normalize_site_keys(self, config: dict[str, Any]) -> dict[str, Any]
Move common site keys placed at the root into the site section.
Provides backward compatibility for configs that set title/baseurl/etc. at the root of _default/*.yaml instead of under [site].
Parameters
| Name | Type | Description |
|---|---|---|
config |
— |
Returns
dict[str, Any]