A simple plugin system for Python with async hooks support.
- Decorator-based API: Define hooks with
@simplug.specand implement with@simplug.impl - Async support: First-class async hooks with sync/async bridging
- Flexible result collection: 18 built-in strategies for collecting plugin results
- Priority system: Control plugin execution order
- Setuptools entrypoints: Load plugins from installed packages
- Singleton per project: Same instance returned for same project name
pip install -U simplugfrom simplug import Simplug
# Create a plugin manager
simplug = Simplug('myproject')
# Define a hook specification
class MySpec:
@simplug.spec
def process_data(self, data):
"""Process data in plugins."""
# Implement the hook in plugins
class PluginA:
@simplug.impl
def process_data(self, data):
return data.upper()
class PluginB:
@simplug.impl
def process_data(self, data):
return data.lower()
# Register plugins
simplug.register(PluginA, PluginB)
# Call the hook
results = simplug.hooks.process_data("Hello")
print(results) # ['HELLO', 'hello']Full documentation is available at https://pwwang.github.io/simplug/
- Define hooks - Specify what plugins can customize
- Implement hooks - Create plugins with implementations
- Register plugins - Load plugins into your application
- Call hooks - Trigger plugin execution
For detailed guides and API reference, see the full documentation.
See the examples directory for complete examples:
examples/toy.py- A minimal 30-line demoexamples/complete/- Full example with setuptools entrypoints
MIT