🐍 Using 3rd party python packages
If your module relies on external Python libraries that are not part of the standard library or the core bot dependencies, you must declare them to ensure they are installed when your module is loaded.
Declaring Dependencies (requirements.txt)
- Create a file named
requirements.txt
in the root directory of your module. - List the required packages in this file, one package per line, following the standard pip requirements file format. You can specify versions if needed.
Automatic Dependency Management
The ModuleManager
(used by ModuleLoader
) handles dependencies automatically:
- Installation/Update: When a module is loaded (
load_module
) or updated (update_from_git
), if arequirements.txt
file exists and dependency updates are enabled (config.update_deps_at_load
), the manager runspip install -U -r requirements.txt
. This installs or updates the listed packages and their dependencies. - Uninstallation: When a module is uninstalled (
uninstall_module
), the manager attempts to uninstall the packages listed in itsrequirements.txt
. - Shared Dependencies: Crucially, the uninstallation process is designed to be safe for shared dependencies. A package is only uninstalled if no other loaded module also lists it in its
requirements.txt
. This prevents removing a package that another module still needs. Theuninstall_module
anduninstall_mod_deps
functions require the current dependency map (loader.get_modules_deps()
) to perform this check.
This system ensures that your module has the necessary libraries available without interfering with other modules or requiring manual pip commands from the user after installing your module.