Skip to main content

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.

The importer module provides utilities for dynamically resolving Python constructs from their fully-qualified string names. It supports PEP 420 implicit namespace packages and is used internally by init_app_conf and stdlogging to allow class names to be supplied as configuration strings.

importer

Resolves a fully-qualified dotted string to the corresponding Python construct (class, function, module, etc.).
from alexber.utils.importer import importer

# Resolve a class
OrderedDict = importer('collections.OrderedDict')
instance = OrderedDict()

# Resolve a function
chain = importer('itertools.chain')

# Resolve a submodule
ymlparsers = importer('alexber.utils.ymlparsers')
target
str
required
Fully-qualified dotted name of the Python construct to resolve (e.g. 'alexber.utils.init_app_conf.AppConfParser').
Returns: The resolved Python object (class, function, module, etc.). Raises: ImportError — if any component of the path cannot be imported. AttributeError — if a component exists in the module but cannot be retrieved.
Only compile-time constructs are supported. Instances are never returned; use new_instance() to create instances.

new_instance

Resolves a dotted string name and, if it refers to a class, instantiates it with the supplied arguments.
from alexber.utils.importer import new_instance

# Create an instance of a class specified by name
parser = new_instance(
    'alexber.utils.init_app_conf.AppConfParser',
    implicit_convert=True,
)

# If target is not a class, it is returned as-is
fn = new_instance('itertools.chain')  # returns the chain function
target
str
required
Fully-qualified dotted name of the class (or other construct) to resolve.
*args
any
Positional arguments forwarded to the class constructor (__new__ / __init__).
**kwargs
any
Keyword arguments forwarded to the class constructor.
Returns: An instance of the resolved class, or the resolved object itself if it is not a class.

Build docs developers (and LLMs) love