Plushy is a plugin framework for Python applications. It does four jobs:
- Discover plugins shipped as installed packages, from entry points or a build-time index, without importing them until they are loaded.
- Load them with a predictable lifecycle: declared requirements, teardown on unload, per-plugin error isolation.
- Dispatch to them through typed hooks, sync and async.
- Gate them with
typing.Protocol contracts and host-controlled enable/disable.
Pluggy is embedded as the sync dispatch engine. Discovery, lifecycle, contracts, enablement and the async caller are Plushy's own.
Install
uv add plushy
Requires Python 3.11+. Installs the plushy library and the plushy index command. Plushy is not on PyPI yet; until it is, see Installation.
Hooks
from plushy import Plugin, PluginManager, hookimpl, hookspec
class Spec:
@hookspec
def render_block(self, block: dict) -> str | None: ...
class Charts(Plugin):
namespace = "acme.renderers"
name = "charts"
@hookimpl
def render_block(self, block):
if block["type"] == "chart":
return f"<figure data-chart='{block['spec']}'></figure>"
return None
pm = PluginManager("acme.renderers", hookspec=Spec)
pm.register(Charts)
pm.load_all()
pm.hook.render_block(block={"type": "chart", "spec": "x"})
# ["<figure data-chart='x'></figure>"]
# in async hosts: await pm.hook.render_block.aio(block={"type": "chart", "spec": "x"})
A plugin's hookimpls take part in dispatch only while it is loaded and enabled. pm.disable("charts") takes it out at once; pm.enable("charts") puts it back without reloading it.
Distributing a plugin
Instead of calling register(), a plugin package declares an entry point in the namespace's group:
[project.entry-points."acme.renderers"]
charts = "acme_charts:Charts"
Any host running PluginManager("acme.renderers") finds it after installation, with no change to the host.
Lifecycle: requirements and teardown
load() may return a value (pull-style: backend = pm.load("s3")), or be a generator whose code after the yield runs when the plugin is unloaded. requires names plugins to load first.
class Db(Plugin):
namespace = "acme.app"
name = "db"
def load(self):
conn = connect()
yield conn # the load result
conn.close() # runs on pm.unload("db") or pm.refresh()
class Cache(Plugin):
namespace = "acme.app"
name = "cache"
requires = ("db",) # loaded first; cycles raise
def load(self):
...
load_all() loads in name order (requirements pulled forward), isolates failures, and keeps each one: pm.error(name) returns the exception.
Documentation
The documentation site is built from docs/ with Zensical (cd docs && make serve):
- Quick Start: a host and a plugin package in five minutes.
- Guides: writing plugins, hooks, async, enablement, contracts, errors, discovery, testing.
- Python API and Known Limitations.
- Pluggy vs. Plushy: what Plushy adds, and when Pluggy alone is enough.
Status
0.1.0, the first release. Tested on Python 3.11 to 3.15. Before 1.0, minor releases may change the API; the changelog says how. Known limits: no async hook wrappers, no filesystem watching, no dependency-injection container (instantiation goes through a single factory reserved for one).
License
Apache License 2.0. See LICENSE.