Quickstart
Prerequisites
Getting Started
2
A working example
from gl_plugin.plugin.plugin import Plugin
from gl_plugin.plugin.handler import PluginHandler
from gl_plugin.plugin.manager import PluginManager
from typing import Any, Dict
# The handler
class HelloPluginHandler(PluginHandler):
def __init__(self) -> None:
super().__init__()
@classmethod
def create_injections(cls, instance: Any) -> Dict[str, Any]:
return dict()
@classmethod
def initialize_plugin(cls, instance: Any, plugin: Any) -> None:
pass
# The plugin
@Plugin.for_handler(HelloPluginHandler)
class HelloPlugin(Plugin):
name = "HelloPlugin"
version = "0.1.0"
description = "A simple greeting plugin"
def greet(self, name: str) -> str:
return f"Hello, {name}!"
# Execution
handler = HelloPluginHandler()
manager = PluginManager(handlers=[handler])
manager.register_plugin(HelloPlugin)
hello_plugin = manager.get_plugin("HelloPlugin")
print(hello_plugin.greet("samuel"))4
Explaining the Components
Plugin Handler
from gl_plugin.plugin.handler import PluginHandler
from typing import Any, Dict
class HelloPluginHandler(PluginHandler):
def __init__(self) -> None:
super().__init__()
@classmethod
def create_injections(cls, instance: Any) -> Dict[str, Any]:
return dict() # No injections for this example
@classmethod
def initialize_plugin(cls, instance: Any, plugin: Any) -> None:
pass # No custom initialization neededCreating the Plugin
from gl_plugin.plugin.plugin import Plugin
@Plugin.for_handler(HelloPluginHandler)
class HelloPlugin(Plugin):
name = "HelloPlugin"
version = "0.1.0"
description = "A simple greeting plugin"
def greet(self, name: str) -> str:
return f"Hello, {name}!"Wiring up into the Manager
from gl_plugin.plugin.manager import PluginManager
manager = PluginManager(handlers=[HelloPluginHandler()])
manager.register_plugin(HelloPlugin)
hello_plugin = manager.get_plugin("HelloPlugin")
print(hello_plugin.greet("samuel")) # Output: Hello, samuel!Last updated
Was this helpful?