Skip to content

kxi-toolkit: Import Utilities

Utilities for managing Python module imports at runtime.

Useful when a module must be reloaded between calls (e.g. hot-reloading UDA code without restarting the process).

Functions:

  • clear_imports – Remove one or more modules (and all their submodules) from sys.modules.

clear_imports

clear_imports(modules)

Remove one or more modules (and all their submodules) from sys.modules.

Forces a fresh import the next time any of the removed modules are imported. Accepts either module objects or fully-qualified module name strings.

Parameters:

  • modules (list[str | ModuleType]) – Modules to evict from the import cache. Each entry may be a ModuleType (e.g. import mymod; clear_imports([mymod])) or a name string (e.g. clear_imports(["mypackage.submod"])).
Example
import my_uda_module
from kxi_toolkit import clear_imports

clear_imports([my_uda_module])
import my_uda_module  # re-imported fresh
Back to top