r/madeinpython • u/Win_ipedia • 3h ago
I built a registerless plugin system based on classes for Python
Overview
Put simply, pyrig-runtime is a plugin system based on classes that declare functionality through code, and via subclassing these classes any state and functionality can be changed, removed or extended by overriding the methods of parent classes. For pyrig-runtime itself this applies to the CLI class it provides.
Specifically, pyrig-runtime defines one base class DependencySubclass at the root of this plugin system. All classes that inherit from it are automatically discoverable. The discovery is achieved as follows: pyrig-runtime builds a directed graph from all installed dependencies in the current Python environment, and finds all packages that have pyrig-runtime as their ancestor in the graph. Those packages are then imported and scanned for any classes that inherit from DependencySubclass. Through the DependencySubclass base class, every subclass has a .leaf() method that returns the leaf class of the inheritance tree. If several leaf classes are found by the discovery mechanism, they are dynamically merged into a single class with multiple inheritance. This is what lets independently installed packages cooperatively extend the same piece of behaviour. It is then simply possible in code logic to access the leaf and work with it.
Features
- Plugin discovery via classes — define a base class and its subclasses are discovered automatically across every installed package that depends on it without the need for registration. Learn more.
Documentation
For anything beyond this overview, see the Documentation.
