Plugin architecture is quite handy when you are designing a developer-facing library. A lot of times I wanted to allow users to inject their code in some way to extend the core library functions and add domain-specific customizations. I found a great approach while going through tox source code and discovered Pluggy which builds on top of Python’s entry_point feature. I was amazed to know thatentry_point is not just for CLI, but a clean plugin system that comes with Python.

In a nutshell, Pluggy provides you with a great interface to define specs for hooks in your library that external libraries can register to. At runtime, the registered functions are loaded and called sequentially in LIFO order.

References: