easyidp.config.EasyIDPConfig¶
- class easyidp.config.EasyIDPConfig(config_path: Path = <factory>, data_dir: Path = <factory>, log_level: str = 'INFO', show_banner: bool = True)¶
JSON-backed package configuration.
- Parameters:
config_path (pathlib.Path, optional) – JSON config file path. Defaults to the platform user config path.
- Returns:
Mutable session configuration object.
- Return type:
Examples
>>> from pathlib import Path >>> import tempfile >>> tmp = tempfile.TemporaryDirectory() >>> cfg = EasyIDPConfig(config_path=Path(tmp.name) / "config.json") >>> isinstance(cfg.set(log_level="DEBUG"), EasyIDPConfig) True >>> cfg.get("log_level") 'DEBUG' >>> tmp.cleanup()
Notes
set()andreset()persist JSON immediately.get()re-reads the file on each call so manual edits are visible.- __init__(config_path: Path = <factory>, data_dir: Path = <factory>, log_level: str = 'INFO', show_banner: bool = True) None¶
Methods
__init__(config_path, data_dir, log_level, ...)get([key])Return current config value(s).
reset()Restore factory defaults and persist JSON immediately.
set(**kwargs)Update config values and persist JSON immediately.
to_dict()Attributes
log_levelshow_bannerconfig_pathdata_dir- get(key: str | None = None) Any¶
Return current config value(s).
- Parameters:
key (str or None, optional) – Config key name.
Nonereturns a plain dict snapshot.- Returns:
Value for key, or a
dictwith all known settings.- Return type:
Any
- Raises:
KeyError – If key is not a recognised config key.
Examples
>>> from pathlib import Path >>> import tempfile >>> tmp = tempfile.TemporaryDirectory() >>> cfg = EasyIDPConfig(config_path=Path(tmp.name) / "config.json") >>> cfg.get("log_level") 'INFO' >>> sorted(cfg.get()) ['data_dir', 'log_level', 'show_banner'] >>> tmp.cleanup()
- reset() EasyIDPConfig¶
Restore factory defaults and persist JSON immediately.
- Returns:
Self (fluent API).
- Return type:
Examples
>>> from pathlib import Path >>> import tempfile >>> tmp = tempfile.TemporaryDirectory() >>> cfg = EasyIDPConfig(config_path=Path(tmp.name) / "config.json") >>> isinstance(cfg.set(log_level="DEBUG"), EasyIDPConfig) True >>> cfg.reset().get("log_level") 'INFO' >>> tmp.cleanup()
- set(**kwargs: Any) EasyIDPConfig¶
Update config values and persist JSON immediately.
- Parameters:
**kwargs (Any) – One or more recognised config keys with new values.
- Returns:
Self (fluent API).
- Return type:
- Raises:
KeyError – If any key in kwargs is not recognised.
Examples
>>> from pathlib import Path >>> import tempfile >>> tmp = tempfile.TemporaryDirectory() >>> cfg = EasyIDPConfig(config_path=Path(tmp.name) / "config.json") >>> isinstance(cfg.set(log_level="DEBUG", show_banner=False), EasyIDPConfig) True >>> cfg.get("show_banner") False >>> tmp.cleanup()