This page shows four practical examples that cover the most commonly used parts of AlexBerUtils. Each example uses real code patterns from the library.Documentation 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.
Install the package before running any examples:
python -m pip install -U alex-ber-utils
For YAML examples, also run: python -m pip install alex-ber-utils[yml]Thread-safe object access with LockingProxy
LockingProxy wraps any object and ensures every attribute access, method call, item get/set, and iteration is guarded by a lock. It composes multiple locking mixins (LockingAccessMixin, LockingIterableMixin, LockingCallableMixin, etc.) into a single transparent proxy.
Wrap a shared object
Create an
RLock, wrap your object with LockingProxy, and use the proxy from any thread:Running async code from a sync context with lift_to_async
lift_to_async lets you call an async function from synchronous code while preserving the current ContextVar context. This is useful in worker threads that need to drive async operations without owning an event loop.
Initialize the event loop config
Call
initConfig() once during application startup from an async context (it requires a running event loop):Parsing app configuration with parse_config
parse_config in init_app_conf merges YAML configuration files with CLI arguments. It supports profile layering (config.yml → config-dev.yml → config-local.yml) and implicit type conversion.
Initialize and parse
Call
initConfig() once before your first parse_config() call, then use the returned dict throughout your application:The
general.profiles key controls which profile YAML files are layered on top of the base config.yml. For example, a profile of ["dev", "local"] causes config-dev.yml then config-local.yml to be merged in order, with later files taking precedence.Simple YAML loading with ymlparsers.load
ymlparsers.load is a thin wrapper around HiYaPyCo that adds Jinja2 variable substitution and returns an OrderedDict. Use it when you need low-level YAML loading without the full parse_config pipeline.
Load multiple YAML files (merge)
Pass multiple file paths to merge them in order. Later files override earlier ones:
Next steps
Concurrency & Async
Deep dive into
RLock, LockingProxy, exec_in_executor, and AsyncExecutionQueue.App configuration
Full reference for
parse_config profile layering, white-listing, and type conversion.YAML utilities
All options for
ymlparsers.load, as_str, and Jinja2 variable substitution.Async cache
LRU/LFU caching with TTL support for async workloads.
