Skip to content

🐍 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)

  1. Create a file named requirements.txt in the root directory of your module.
  2. 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:

  1. Installation/Update: When a module is loaded (load_module) or updated (update_from_git), if a requirements.txt file exists and dependency updates are enabled (config.update_deps_at_load), the manager runs pip install -U -r requirements.txt. This installs or updates the listed packages and their dependencies.
  2. Uninstallation: When a module is uninstalled (uninstall_module), the manager attempts to uninstall the packages listed in its requirements.txt.
  3. 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. The uninstall_module and uninstall_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.