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.
ymlparsers module is a streamlined wrapper around the HiYaPyCo library. It adds thread-safe Jinja2 variable substitution, a context manager to disable substitution on demand, and a consistent API for loading and dumping YAML.
This module is the low-level backend for init_app_conf. It can also be used independently.
Setup
CallinitConfig() once at application startup before calling any other function:
load() and safe_dump().
Loading YAML files
load(yaml_files, **kwargs)
Loads and merges one or more YAML files hierarchically. Files listed later override earlier ones. Returns an OrderedDict.
By default:
- Lists are replaced, not merged (
mergelists=False) - Jinja2 variable substitution is enabled (
interpolate=True) - Values are cast to Python types after interpolation (
castinterpolated=True) - Method is
METHOD_SUBSTITUTE(later files override earlier ones)
config.yml:
config-dev.yml that sets inner_host_name: yahoo.com, the template resolves to 'ping yahoo.com'.
Parameters
Ordered list of YAML file paths or YAML strings. Files are merged left to right — each subsequent file overrides the previous.
Merge method. One of
hiyapyco.METHOD_SIMPLE, METHOD_MERGE, or METHOD_SUBSTITUTE (default).Whether to merge lists. Defaults to
False (lists are replaced).Whether to perform Jinja2 variable substitution. Defaults to
True.Whether to cast interpolated string values to Python types. Defaults to
True.File encoding. Defaults to
'utf-8'.Raise an error if a file does not exist. Defaults to
True.Disabling variable substitution
DisableVarSubst()
A context manager that temporarily disables Jinja2 variable substitution inside load(). This is used internally by init_app_conf to read the raw base config (including unresolved {{...}} templates) before merging.
HiYaPyCo.jinja2Lock and restores the original delimiter strings in the finally block, even if an exception is raised.
You can also pass a custom Jinja2 environment and lock:
Parameters
Custom Jinja2 environment to disable substitution on. Defaults to
HiYaPyCo.jinja2ctx.Lock for thread safety. Must be the same lock used by
load(). Defaults to HiYaPyCo.jinja2Lock.
Cannot be provided without jinja2ctx.Dumping YAML
safe_dump(data, stream=None, **kwargs)
Dumps a Python object to YAML format. Supports primitive types, lists, dicts, and collections.OrderedDict.
By default:
- Block style (
default_flow_style=False) - Key order is preserved (
sort_keys=False)
Parameters
The Python object to serialize.
A writable stream. If
None, returns a string (via yaml.dump_all semantics).Controls YAML style.
False (default) uses block style. Pass True for inline/flow style.Whether to sort dictionary keys alphabetically. Defaults to
False (insertion order preserved).as_str(data, **kwargs)
Returns a string representation of the data in YAML format. A convenience wrapper around safe_dump().
Parameters
The Python object to serialize to a YAML string.
**kwargs as safe_dump().
initConfig(**kwargs)
Initializes the module. Safe to call with no arguments. Must be called before load() or safe_dump().
Thread lock for synchronization in
DisableVarSubst and load(). Defaults to a new RLock().
Available as HiYaPyCo.jinja2Lock after initialization.Configuration dict for the Jinja2 Available as
Environment. Supports all Environment keyword arguments plus a globals sub-key:undefined: defaults toDebugUndefinedglobals: dict of global functions available in templates;uname(platform.uname) is always injected
HiYaPyCo.jinja2ctx after initialization.Default keyword arguments for
load(). Overrides the built-in defaults:Default keyword arguments for
safe_dump() and as_str(). Overrides the built-in defaults:Customizing defaults example
Thread safety
load() acquires HiYaPyCo.jinja2Lock for every interpolated string. DisableVarSubst also acquires the same lock. Both are safe to use concurrently from multiple threads — a common pattern is one thread loading with substitution and another loading without it simultaneously.