Features
Hook system
Register callbacks for custom events with the @hook decorator. Simple yet powerful.
Framework agnostic
Works with any Python application. No framework lock-in.
Async/await support
Native async hook execution for non-blocking plugin architectures.
Hook priorities
Control execution order with priority values. Higher priority runs first.
Data filtering
Each hook can modify and transform data as it passes through the chain.
Error isolation
Plugin errors are caught and handled. One bad plugin won't crash your application.
Timeout protection
Set timeouts to prevent slow plugins from blocking the entire system.
Event namespacing
Organize events hierarchically with wildcard support for flexible subscriptions.
Plugin discovery
Auto-discover plugins from directories. Hot reload without restarting.
Quick example
from nitro_dispatch import Dispatcher, hook
dispatcher = Dispatcher()
class AnalyticsPlugin:
name = "analytics"
@hook("page.render", priority=50)
def track_render(self, data):
print(f"Rendering: {data['title']}")
return data
@hook("page.after_render")
def inject_script(self, data):
html = data.get("output", "")
data["output"] = html.replace(
"</body>",
"<script src='/analytics.js'></script></body>"
)
return data
dispatcher.register_plugin(AnalyticsPlugin())
dispatcher.dispatch("page.render", {"title": "Home"})