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.0

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.0
File Size Uploaded Provenance Actions
plushy-0.1.0.tar.gz 20.3 kB Without provenance Details for plushy-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 44.3 kB

Release files / plushy-0.1.0.tar.gz

Download URL plushy-0.1.0.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a96ca5c543ff8cafd1a064c64a160f86bd2670dd16c30021b0ddc315ef7255cd
BLAKE2b-256 checksum
How to use checksums
3c67e55f73681f34748cdbe463ea58b349ff5d5e59f7f1cb3c532433d97ce4a3
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.0-py3-none-any.whl

Download URL plushy-0.1.0-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2c949872b785fab0795b3a36b597b8dc0e041ceab65e1634ac2fad5f5bb4cd7
BLAKE2b-256 checksum
How to use checksums
c82ccf75be0d6186f155f4cfae9ceab27759f211e5c40553c82e3c306eb7982b
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.0

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