Skip to main content

create_module

Creates and registers a new module instance in sys.modules using a specified base class and attributes. The function dynamically builds the module's fully qualified domain name and populates its namespace with processed attribute values.

def create_module(
name: string,
attrs: dict,
cls_attrs: dict = null,
pkg: module = null,
base: class = LazyModule,
prepare_attr: callable = null
) - > LazyModule

Dynamically creates and registers a new module instance in sys.modules using a specified base class and attribute set.

Parameters​

NameTypeDescription
namestringThe full name of the module to be created.
attrsdictA dictionary of attributes and values to be injected into the module's namespace.
cls_attrsdict = nullAdditional attributes to be set on the module's class during instantiation.
pkgmodule = nullThe parent package object used to determine the module's fully qualified domain name.
baseclass = LazyModuleThe base class from which the new module instance will inherit.
prepare_attrcallable = nullAn optional transformation function applied to each value in the attrs dictionary before assignment.

Returns​

TypeDescription
LazyModuleThe newly created and registered module instance populated with the provided attributes.