PyStaticConfiguration

raw JSON →
0.11.1 verified Fri May 01 auth: no python maintenance

A Python library for loading static configuration from YAML, JSON, and Python files. Current version 0.11.1, released July 2021. Infrequently updated; supports Python >=3.6.

pip install pystaticconfiguration
error ModuleNotFoundError: No module named 'staticconf'
cause The package is installed as 'pystaticconfiguration', but the import uses 'staticconf'.
fix
Run 'pip install pystaticconfiguration' and then import as 'import staticconf'.
error AttributeError: module 'staticconf' has no attribute 'YamlLoader'
cause YamlLoader is in staticconf.loader submodule, not directly in staticconf.
fix
Use 'from staticconf.loader import YamlLoader'.
gotcha The package name is 'pystaticconfiguration', but the Python module is 'staticconf'. Import from 'staticconf' directly.
fix Use 'from staticconf.config import Configuration' not 'from pystaticconfiguration import ...'.
gotcha Configuration must be reset between tests: call Configuration.reset() to clear previous settings, otherwise you may see stale defaults.
fix In test setup, do 'config = Configuration(); config.clear()' or use 'config.reset()'.
deprecated Using 'staticconf.build' (the old module) is deprecated. Use 'staticconf.config' instead.
fix Replace 'from staticconf import build' with 'from staticconf.config import Configuration'.

Loads a YAML config file and retrieves a key.

import os
from staticconf.config import Configuration
from staticconf.loader import YamlLoader

config = Configuration()
loader = YamlLoader('config.yaml')
config.update_from_loader(loader)
print(config.get('key', default='not found'))