Skip to main content

Plugin and hook calling mechanisms for python

Project description

Documentation Status

Please read the docs to learn more!

A definitive example

import aiopluggy, asyncio

hookspec = aiopluggy.HookspecMarker("myproject")
hookimpl = aiopluggy.HookimplMarker("myproject")


class MySpec(object):
    """A hook specification namespace.
    """
    @hookspec
    def myhook(self, arg1, arg2):
        """My special little hook that you can customize.
        """


class Plugin_1(object):
    """A hook implementation namespace.
    """
    @hookimpl.asyncio
    async def myhook(self, arg1, arg2):
        print("inside Plugin_1.myhook()")
        return arg1 + arg2


class Plugin_2(object):
    """A 2nd hook implementation namespace.
    """
    @hookimpl
    def myhook(self, arg1, arg2):
        print("inside Plugin_2.myhook()")
        return arg1 - arg2


async def main():
    # create a manager and add the spec
    pm = aiopluggy.PluginManager("myproject")
    pm.register_specs(MySpec)

    # register plugins
    await pm.register(Plugin_1())
    await pm.register(Plugin_2())

    # call our `myhook` hook
    results = await pm.hook.myhook(arg1=1, arg2=2)
    print(results)


asyncio.get_event_loop.run_until_complete(main())

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

aiopluggy-0.1.5rc3.tar.gz (12.8 kB view details)

Uploaded Source

File details

Details for the file aiopluggy-0.1.5rc3.tar.gz.

File metadata

File hashes

Hashes for aiopluggy-0.1.5rc3.tar.gz
Algorithm Hash digest
SHA256 b35386853c0ad32004aff7015d219d9c3d92f9a77e96aafaca8afec87e0ab141
MD5 89c72925006c3efdc400b9871c751b6b
BLAKE2b-256 e1bf82d53651603f773043919d70c598db06a22b0e2d485cf43a3ec652868781

See more details on using hashes here.

Supported by

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