Configuration System¶
Overview¶
Frameworm uses a powerful YAML-based configuration system with support for: - Config inheritance - Environment variable interpolation - CLI overrides - Pydantic validation
Basic Usage¶
Loading a Config¶
from frameworm.core import Config
cfg = Config('configs/model.yaml')
print(cfg.model.name) # Access with dot notation
print(cfg['model']['name']) # Or dict-style
Config Inheritance¶
Configs can inherit from other configs using the _base_ key:
# configs/base.yaml
training:
epochs: 100
batch_size: 32
# configs/gan.yaml
_base_: ./base.yaml
training:
epochs: 200 # Override
model:
type: gan # Add new
Multiple levels of inheritance are supported.
Environment Variables¶
Use ${VAR_NAME} syntax for environment variables:
CLI Overrides¶
Override config values from command line:
Validation¶
Define validation schemas with Pydantic:
from pydantic import BaseModel, Field
class ModelConfig(BaseModel):
name: str
dim: int = Field(gt=0)
cfg = Config('model.yaml')
validated = cfg.validate(ModelConfig)
Best Practices¶
- Use inheritance - Create a base config and extend it
- Validate configs - Define schemas for important configs
- Environment variables - For paths and secrets
- Freeze configs - After loading to prevent accidental modifications
- Dump configs - Save merged configs for reproducibility
Examples¶
See examples/config_examples.py for more usage patterns.