Skip to main content

plugin and hook calling mechanisms for python

Project description

pypi conda-forge versions github-actions Join the chat at https://gitter.im/pytest-dev/pluggy black Code coverage Status

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pluggy-1.6.0.tar.gz (69.4 kB view details)

Uploaded Source

Built Distribution

pluggy-1.6.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file pluggy-1.6.0.tar.gz.

File metadata

  • Download URL: pluggy-1.6.0.tar.gz
  • Upload date:
  • Size: 69.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pluggy-1.6.0.tar.gz
Algorithm Hash digest
SHA256 7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3
MD5 54391218af778acb006c2d915085d469
BLAKE2b-256 f9e23e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779

See more details on using hashes here.

Provenance

The following attestation bundles were made for pluggy-1.6.0.tar.gz:

Publisher: main.yml on pytest-dev/pluggy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pluggy-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: pluggy-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pluggy-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746
MD5 e107bd9fd0c26746617d74bac26fa0c5
BLAKE2b-256 54204d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pluggy-1.6.0-py3-none-any.whl:

Publisher: main.yml on pytest-dev/pluggy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page