Skip to main content
Plushy: Typed plugins for Python

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):

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.

Metadata

Release files for plushy 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plushy 0.1.1
File Size Uploaded Provenance Actions
plushy-0.1.1.tar.gz 21.8 kB Without provenance Details for plushy-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for plushy 0.1.1
File Interpreter ABI Platform Actions
plushy-0.1.1-py3-none-any.whl Python 3 none any Details for plushy-0.1.1-py3-none-any.whl

Total release size: 46.8 kB

Release files / plushy-0.1.1.tar.gz

Download URL plushy-0.1.1.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ea9a2622579c25748d5550608de17631e22f7c256b398bd3f77fc3ef6b92a9b2
BLAKE2b-256 checksum
How to use checksums
d433d865c6dd9fe9798e7c381e9f5d4ba648e66eac18e2f1a9878e15b9daf710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / plushy-0.1.1-py3-none-any.whl

Download URL plushy-0.1.1-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7600475cea1f6eeb67327c61fdc86724c4317bf4b2a5cedb70e665e7ef36713
BLAKE2b-256 checksum
How to use checksums
0caae78326f8faaf27d52f9a6645543e677d20eb641a7b7f4cb1ca1649512f0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for plushy 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page