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:

EasyIDPConfig

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() and reset() 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_level

show_banner

config_path

data_dir

get(key: str | None = None) Any

Return current config value(s).

Parameters:

key (str or None, optional) – Config key name. None returns a plain dict snapshot.

Returns:

Value for key, or a dict with 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:

EasyIDPConfig

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:

EasyIDPConfig

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()