plugins_api.utils.plugin_utils
Plugin utilities.
This module contains utility functions for plugin discovery and management.
Functions
| Name | Description |
|---|---|
find_plugins_in_module | Find and return all plugin classes defined in the specified module. |
get_plugin_class | Return the class object of a plugin based on its ID. |
get_plugin_instance | Get an instance of a connection plugin. |
get_plugin_version | Get the version of a plugin. |
get_plugins | Retrieve dynamically all implementations of plugins in apps, optionally filtered by plugin type. |
is_plugin_in_dev_mode | Check if a plugin is installed in development mode (editable install). |
reload_plugins | Retrieve all available plugins. |
loggerattributemodule attribute#
logger = logging.getLogger(__name__)pluginsattributemodule attribute#
plugins: list[type[MadbotPlugin]] = []find_plugins_in_modulefunction#
def find_plugins_in_module(module: types.ModuleType) -> list[type[MadbotPlugin]]Find and return all plugin classes defined in the specified module.
Parameters
| Name | Type | Description |
|---|---|---|
module | any | The module to inspect for plugin classes. |
Returns
list- A list of plugin classes found in the module.
get_plugin_classfunction#
def get_plugin_class(plugin_id: str) -> type[MadbotPlugin]Return the class object of a plugin based on its ID.
Parameters
| Name | Type | Description |
|---|---|---|
plugin_id | str | The unique ID of the plugin in the module.class format. |
Returns
type- The class object of the plugin.
Raises
PluginNotFoundError- If the plugin cannot be found.
get_plugin_instancefunction#
def get_plugin_instance(plugin_id: str, connection_parameters: dict[str, Any], settings: dict[str, Settings] | None = None) -> ConnectionPluginGet an instance of a connection plugin.
Parameters
Returns
ConnectionPlugin- The plugin instance.
Raises
InvalidPluginTypeError- If the plugin cannot be instantiated.
get_plugin_versionfunction#
def get_plugin_version(plugin_class: type[MadbotPlugin]) -> str | NoneGet the version of a plugin.
This function tries multiple methods to retrieve the plugin version:
- First tries to get version from the plugin’s init.py module (version)
- Falls back to using importlib.metadata.distribution() to get the installed package version
- Returns None if version cannot be determined
Parameters
| Name | Type | Description |
|---|---|---|
plugin_class | Type[MadbotPlugin] | The plugin class to get the version for |
get_pluginsfunction#
def get_plugins(plugin_type: type[MadbotPlugin] | None = None) -> list[type[MadbotPlugin]]Retrieve dynamically all implementations of plugins in apps, optionally filtered by plugin type.
Parameters
Returns
list- A list of plugins.
is_plugin_in_dev_modefunction#
def is_plugin_in_dev_mode(plugin_class: type[MadbotPlugin]) -> boolCheck if a plugin is installed in development mode (editable install).
This function uses Python’s importlib.metadata to check the package’s direct_url.json file, which contains information about how the package was installed. For editable installs, this file contains: {“dir_info”: {“editable”: true}, “url”: “file:///path/to/source”}
Parameters
| Name | Type | Description |
|---|---|---|
plugin_class | Type[MadbotPlugin] | The plugin class to check |
Returns
bool- True if the plugin is installed in editable mode, False otherwise
reload_pluginsfunction#
def reload_plugins() -> NoneRetrieve all available plugins.

