Skip to content

Cheat Sheet

You want to… Use
Write a plugin class P(Plugin): namespace = "…"; name = "…"
Write a one-function plugin @plugin("namespace")
Publish a plugin [project.entry-points."namespace"] in its pyproject.toml
Let a plugin decline to load override should_load()
Pass the application to plugins PluginManager(…, load_args=(app,), load_kwargs={…})
Load every plugin pm.load_all(), or PluginManager(…, eager=True)
Get one plugin's object pm.load("name")
Get a new object on every call PluginManager(…, cache=False)
Declare an extension point @hookspec on a method of a spec class; PluginManager(…, hookspec=Spec)
Implement it @hookimpl on a plugin method
Call it pm.hook.name(arg=value)
Stop at the first answer @hookspec(firstresult=True)
Run around the other implementations @hookimpl(wrapper=True) and result = yield
Change the call order @hookimpl(tryfirst=True), @hookimpl(trylast=True)
Call from async code await pm.hook.name.aio(…); concurrently: .aio_gather(…)
Release resources on unload generator load(): yield result, then cleanup; pm.unload("name")
Load another plugin first requires = ("other",)
Leave plugins out PluginManager(…, disabled={"name"}) or enablement=MyPolicy()
Switch a plugin off and on pm.disable("name"), pm.enable("name")
Check the shape of plugins PluginManager(…, contract=MyProtocol)
Warn instead of failing on contracts contract_policy=ContractPolicy(strict=False)
See why a plugin failed pm.state("name"), pm.error("name")
Log plugin events PluginManager(…, listeners=[MyListener()])
Skip entry points (tests) PluginManager(…, discover=False) and pm.register(…)
Ship an index instead of entry points pluxeo index; sources=[IndexFileSource(path)]
Drop-in plugins while developing sources=[NamespacePackageSource("package")]
Pick up new plugins pm.refresh() then pm.load_all()