Pluggy is a Python library for building plugin systems, originally extracted from the pytest project. It uses a hook-based model where hosts define hook specifications with HookspecMarker and plugins implement them with HookimplMarker. Plugin discovery can be done via Python packaging entry points (pyproject.toml) or any custom method. The post walks through a concrete example of building a pluggable htmlize tool, covering hook definition, plugin loading, invocation, and implementation. It then evaluates Pluggy against fundamental plugin infrastructure concepts (discovery, registration, hooks, API exposure) and concludes that while plugin frameworks are generally shallow APIs easy to roll yourself, Pluggy adds value through entry point registration, signature validation, result collection, and plugin ordering features.

7m read timeFrom eli.thegreenplace.net
Post cover image
Table of contents
Defining hooksLoading plugins in the hostInvoking pluginsImplementing hooks in plugins
368 Impressions