# plugins_api.utils.plugin_utils

*module*

Plugin utilities.

This module contains utility functions for plugin discovery and management.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L1-1)

## plugins_api.utils.plugin_utils.logger

*attribute* · *module attribute*

```python
logger = logging.getLogger(__name__)
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L30-30)

## plugins_api.utils.plugin_utils.plugins

*attribute* · *module attribute*

```python
plugins: list[type[MadbotPlugin]] = []
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L175-175)

## plugins_api.utils.plugin_utils.find_plugins_in_module

*function*

```python
def find_plugins_in_module(module: types.ModuleType) -> list[type[MadbotPlugin]]
```

Find and return all plugin classes defined in the specified module.

**Parameters**

- `module` (`any`) — The module to inspect for plugin classes.

**Returns**

- (`list`) — A list of plugin classes found in the module.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L146-172)

## plugins_api.utils.plugin_utils.get_plugin_class

*function*

```python
def get_plugin_class(plugin_id: str) -> type[MadbotPlugin]
```

Return the class object of a plugin based on its ID.

**Parameters**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L258-287)

## plugins_api.utils.plugin_utils.get_plugin_instance

*function*

```python
def get_plugin_instance(plugin_id: str, connection_parameters: dict[str, Any], settings: dict[str, Settings] | None = None) -> ConnectionPlugin
```

Get an instance of a connection plugin.

**Parameters**

- `plugin_id` (`str`) — The unique ID of the plugin in the module.class format.
- `connection_parameters` (`Dict[str, Any]`) — Connection parameters (URLs, credentials, etc.)
- `settings` (`Dict[str, Any]`) (default: `None`) — Settings parameters (only for SubmissionPlugin)

**Returns**

- (`ConnectionPlugin`) — The plugin instance.

**Raises**

- `InvalidPluginTypeError` — If the plugin cannot be instantiated.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L290-335)

## plugins_api.utils.plugin_utils.get_plugin_version

*function*

```python
def get_plugin_version(plugin_class: type[MadbotPlugin]) -> str | None
```

Get the version of a plugin.

This function tries multiple methods to retrieve the plugin version:
1. First tries to get version from the plugin's __init__.py module (__version__)
2. Falls back to using importlib.metadata.distribution() to get the installed package version
3. Returns None if version cannot be determined

**Parameters**

- `plugin_class` (`Type[MadbotPlugin]`) — The plugin class to get the version for

**Returns**

- (`str | None`) — The plugin version string, or None if version cannot be determined

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L83-143)

## plugins_api.utils.plugin_utils.get_plugins

*function*

```python
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**

- `plugin_type` (`type`) (default: `None`) — The type of plugins to filter (DataPlugin or SubmissionPlugin or MetadataFieldDefinitionPlugin).

**Returns**

- (`list`) — A list of plugins.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L178-250)

## plugins_api.utils.plugin_utils.is_plugin_in_dev_mode

*function*

```python
def is_plugin_in_dev_mode(plugin_class: type[MadbotPlugin]) -> bool
```

Check 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**

- `plugin_class` (`Type[MadbotPlugin]`) — The plugin class to check

**Returns**

- (`bool`) — True if the plugin is installed in editable mode, False otherwise

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L33-80)

## plugins_api.utils.plugin_utils.reload_plugins

*function*

```python
def reload_plugins() -> None
```

Retrieve all available plugins.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/plugin_utils.py#L253-255)
