plugin and hook calling mechanisms for python
Project Links
Meta
Author: Holger Krekel
Requires Python: >=3.9
Classifiers
Development Status
- 6 - Mature
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Operating System
- POSIX
- Microsoft :: Windows
- MacOS :: MacOS X
Topic
- Software Development :: Testing
- Software Development :: Libraries
- Utilities
Programming Language
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
- Python :: 3
- Python :: 3 :: Only
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
This is the core framework used by the pytest, tox, and devpi projects.
Please read the docs to learn more!
A definitive example
import pluggy
hookspec = pluggy.HookspecMarker("myproject")
hookimpl = pluggy.HookimplMarker("myproject")
class MySpec:
"""A hook specification namespace."""
@hookspec
def myhook(self, arg1, arg2):
"""My special little hook that you can customize."""
class Plugin_1:
"""A hook implementation namespace."""
@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_1.myhook()")
return arg1 + arg2
class Plugin_2:
"""A 2nd hook implementation namespace."""
@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_2.myhook()")
return arg1 - arg2
# create a manager and add the spec
pm = pluggy.PluginManager("myproject")
pm.add_hookspecs(MySpec)
# register plugins
pm.register(Plugin_1())
pm.register(Plugin_2())
# call our ``myhook`` hook
results = pm.hook.myhook(arg1=1, arg2=2)
print(results)
Running this directly gets us:
$ python docs/examples/toy-example.py inside Plugin_2.myhook() inside Plugin_1.myhook() [-1, 3]
Support pluggy
Open Collective is an online funding platform for open and transparent communities. It provides tools to raise money and share your finances in full transparency.
It is the platform of choice for individuals and companies that want to make one-time or monthly donations directly to the project.
pluggy is part of the pytest-dev project, see more details in the pytest collective.
May 15, 2025
1.6.0
Apr 20, 2024
1.5.0
Jan 24, 2024
1.4.0
Aug 26, 2023
1.3.0
Jun 21, 2023
1.2.0
Jun 19, 2023
1.1.0
Aug 25, 2021
1.0.0
Jun 04, 2020
1.0.0.dev0
Nov 21, 2019
0.13.1
Sep 10, 2019
0.13.0
May 27, 2019
0.12.0
May 07, 2019
0.11.0
May 07, 2019
0.10.0
Feb 24, 2019
0.9.0
Jan 09, 2019
0.8.1
Oct 16, 2018
0.8.0
Jul 28, 2018
0.7.1
Nov 24, 2017
0.6.0
Sep 06, 2017
0.5.2
Aug 29, 2017
0.5.1
Aug 29, 2017
0.5.0
Sep 25, 2016
0.4.0
Sep 17, 2015
0.3.1
May 07, 2015
0.3.0