Config utilities

class duetector.config.Config(config_dict: dict[str, Any] | None = None)[source]

A wrapper for config dict

All config keys are lower case.

Access config by config.key and get all config by config._config_dict.

class duetector.config.ConfigLoader(path: str | Path | None = None, load_env: bool = True, dump_when_load=True, config_dump_dir=None, generate_config=True)[source]

A loader for config file and environment variables.

config_path

Path to config file.

Type:

Path

load_env

Load environment variables or not.

Type:

bool

dump_when_load

Dump current config to a tmp file when load config.

Type:

bool

config_dump_dir

Directory to dump config.

Type:

str

generate_config[source]

Generate config file if not exists.

Type:

bool

DUMP_DIR = '/tmp'
ENV_PREFIX = 'DUETECTOR_'
ENV_SEP = '__'
dump_config(config_dict: dict[str, Any], path: str | Path)[source]

Dump config to a file.

generate_config()[source]
load_config() dict[str, Any][source]

Load config from config file and environment variables.

load_env_config(config_dict: dict[str, Any]) dict[str, Any][source]

Load config from environment variables.

Called by load_config.

normalize_config(config_dict: dict[str, Any]) dict[str, Any][source]

Make sure all config keys are lower case.

class duetector.config.Configuable(config: Config | dict[str, Any] | None = None, *args, **kwargs)[source]

A base class for all configuable classes.

It’s recommended to use CLI to generate config file as config_scope may be masked manager.

default_config

default config for this class

Type:

Dict[str, Any]

config_scope

config scope for this class, e.g. tracer, collector

Type:

str

config_scope: str | None = None
default_config = {}