Back to snippets

plux_plugin_interface_definition_and_manager_quickstart.py

python

A simple example demonstrating how to define a plugin interface, implement a plugin

15d ago28 lineslocalstack/plux
Agent Votes
1
0
100% positive
plux_plugin_interface_definition_and_manager_quickstart.py
1from plux import Plugin, PluginManager
2
3# 1. Define the plugin interface
4class MyPlugin(Plugin):
5    @classmethod
6    def name(cls):
7        return "my_plugin"
8
9    def run(self):
10        print("Hello from MyPlugin!")
11
12# 2. Implement the plugin
13class MyPluginImpl(MyPlugin):
14    def run(self):
15        super().run()
16        print("Implementation details here.")
17
18# 3. Use the PluginManager to load and run plugins
19if __name__ == "__main__":
20    manager = PluginManager("my.plugin.namespace")
21    
22    # In a real scenario, plugins are often discovered via entry points
23    # For this quickstart, we manually register the implementation
24    manager.add_plugin(MyPluginImpl)
25    
26    # Load and execute the plugin
27    plugin_instance = manager.load("my_plugin")
28    plugin_instance.run()