config
YAML-based configuration file loading with support for includes, symbol substitution, and live reloading.
Configuration file syntax
Configuration files use YAML format. Top-level keys map to smisk.config.config attributes:
smisk:
autoreload: True
mvc:
template_dir: templates/
myapp:
db_url: "sqlite:///myapp.db"
Includes
Use the @include directive to split configuration across multiple files:
@include: base.yaml
@inherit
Use @inherit to extend configuration from another file, merging keys recursively rather than replacing them.
Logging
The logging key accepts Python logging.config.dictConfig syntax and is applied automatically on load.
Symbols
Predefined symbols can be used in string values with ${SYMBOL} syntax.
Predefined symbols
| Symbol | Description |
|---|---|
${APPDIR} | Absolute path to the application directory |
${HOSTNAME} | Current machine hostname |
Practical use
from smisk.config import config
config.load("myapp.yaml")
print(config.myapp.db_url)
Attributes
smisk.config.configThe global
Configurationinstance. Import and use this throughout your application.
Functions
smisk.config.Configuration.reload()Reload configuration from disk. Called automatically by the autoreloader.
Classes
- class
smisk.config.Configuration -
A lazy-loading configuration object. Attributes are created dynamically from the YAML keys.
__call__()Shorthand for loading the default configuration file.
__init__()Initialise an empty configuration object.