TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/alex-ber/AlexBerUtils/llms.txt
Use this file to discover all available pages before exploring further.
init_app_conf module is the primary configuration entry point for AlexBerUtils applications. It unifies command-line argument parsing with hierarchical YAML file loading and profile-based overriding into one function call.
How it works
Parse CLI arguments
CLI arguments of the form
--key=value are read first. The special argument --general.config.file (default: config.yml) points to the base YAML file.Load base YAML
The base config file is loaded.
general.profiles determines which additional profile files to layer on top.Apply profile layering
If profiles are
[dev, local], the module loads config.yml, then overrides with config-dev.yml, then config-local.yml.Apply CLI overrides
CLI arguments are applied last, overriding YAML values. Which keys can be overridden is controlled by
general.whiteListSysOverride.Setup
CallinitConfig() once at application startup — typically in the main thread — before calling any other function in this module.
Complete example
Directory layout
config.yml
config-dev.yml
main.py
CLI invocation
Profile system
Profiles allow environment-specific config files to layer on top of the base config.config.yml:
--general.profiles always takes precedence over the YAML value.
general.whiteListSysOverride
By default, any top-level key that exists in the base YAML can be overridden from the CLI. To restrict which keys are CLI-overridable, set general.whiteListSysOverride in the YAML:
--app.host_name will be accepted from the CLI. All other CLI keys (e.g., --app.portal) are silently ignored.
general.listEnsure
Keys listed under general.listEnsure are treated as comma-delimited lists when provided as CLI arguments:
API reference
initConfig(**kwargs)
Initializes the module. Must be called before parse_config(). Safe to call with no arguments.
The parser class to use. Accepts a class object or a fully-qualified class name string.
Defaults to
AppConfParser.Default keyword arguments passed to the parser class constructor. Supported keys:
implicit_convert(bool, defaultTrue): whether to auto-convert string values to Python types.
parse_config(argumentParser=None, args=None, implicit_convert=None)
The main function. Parses CLI arguments and YAML files, returning a fully merged OrderedDict.
An
argparse.ArgumentParser instance. If None, a new one is created automatically.Explicit argument list. If provided,
sys.argv is suppressed. Useful for testing.Controls type conversion for CLI argument values.
None(default): uses the value set ininitConfig()(defaultTrue).True: converts strings to Python types ('1000'→1000,'True'→True,'None'→None).False: all CLI values remain as strings.
OrderedDict with the fully merged configuration. Always includes:
general.config.file— absolute path to the resolved base YAML filegeneral.profiles— the resolved list of active profilesgeneral.whiteListSysOverride— the resolved whitelistgeneral.listEnsure— the resolved list-ensure keys
mask_value(value, implicit_convert=None)
Converts a string value to an appropriate Python type.
The string to convert.
If
None, uses the value from initConfig(). If True, converts to Python built-in types. If False, returns the value as-is.'true', 'True', 'TRUE' all become True.
to_convex_map(d, white_list_flat_keys=None, implicit_convert=None)
Converts a flat dot-notation dictionary into a nested OrderedDict.
A flat dictionary with dot-separated keys, e.g.
{'general.profiles': 'dev', 'app.host_name': 'localhost'}.If provided, only keys that start with one of the listed prefixes are included in the output.
Controls type conversion of values. Defaults to the value set in
initConfig().mask_value() when implicit_convert=True.
merge_list_value_in_dicts(flat_d, d, main_key, sub_key, implicit_convert=None)
Merges a list value from a flat dict and a nested dict. The flat dict value takes precedence when non-empty.
Flat dictionary (typically from parsed CLI args). Key is
main_key + '.' + sub_key.Nested dictionary (typically from parsed YAML). Value is at
d[main_key][sub_key].The top-level key, e.g.
'general'.The nested key, e.g.
'profiles'.Applied only to the
flat_d value. Defaults to the value set in initConfig().