Dynamic Package Loading
The PackageManager allows you to dynamically import Python packages at runtime and
register all their public functions into the executor’s event dictionary.
Basic Usage
from je_load_density import executor
# Load a package and make all its functions available as executor actions
executor.execute_action([
["LD_add_package_to_executor", ["my_custom_package"]]
])
After loading, all functions from the package can be called by name in JSON scripts
or via executor.execute_action().
How It Works
Uses
importlib.util.find_spec()to locate the packageImports the package with
importlib.import_module()Uses
inspect.getmembers()withisfunctionto find all functions in the packageRegisters each function into the executor’s
event_dict
Note
Only top-level functions in the package are registered. Classes, constants, and submodules are not automatically added.
PackageManager API
Method |
Description |
|---|---|
|
Try to import a package. Returns the module or |
|
Import a package and register all its functions into the executor. |
Example: Using a Custom Package
Suppose you have a custom package my_utils with a function compute():
from je_load_density import executor
# Register the package
executor.execute_action([
["LD_add_package_to_executor", ["my_utils"]]
])
# Now you can call compute() by name
executor.execute_action([
["compute", [42]]
])
Using in JSON Scripts
[
["LD_add_package_to_executor", ["my_utils"]],
["compute", [42]]
]