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.
alexber.utils.importer module lets you resolve Python constructs — classes, functions, modules — from plain strings at runtime. This is the foundation for the plugin/strategy pattern used throughout alexber.utils.
importer(dotted_path)
Converts a dotted string path into the Python object it names, recursively importing packages as needed.
| Parameter | Type | Description |
|---|---|---|
dotted_path | str | Fully-qualified dotted path to the target, e.g. "myapp.parsers.YamlParser". |
new_instance() for that.
Only compile-time constructs are supported (classes, functions, modules, constants).
importer will not return an instance of a class.Namespace package support
importer supports PEP 420 implicit namespace packages. If a component does not yet exist on the parent object, the function imports the full path up to that point before retrying the attribute lookup.
new_instance(target, *args, **kwargs)
Like importer, but if the resolved object is a class it instantiates it and returns the instance.
Configuring a parser class via init_app_conf
A common pattern in alexber.utils is accepting a class (or its dotted string path) as a configuration parameter so callers can swap implementations without changing code.
The example below shows how default_parser_cls in init_app_conf uses importer internally:
How the resolution algorithm works
Split the path
The dotted string is split on
'.'. The first component is imported as a top-level module.Walk the remaining components
For each remaining component the function first tries
getattr. If the attribute does not exist it imports the full path up to that point (triggering __init__.py execution) and tries getattr again.