Skip to main content

Yet another python hook system

Project description

yaphs

pipeline status coverage report

Yet another python hook system for python 2.7/3.x

Usage

Basic usage

Import yaphs

from yaphs import Hook

Register foo as a hook-compatible function

@Hook
def foo(*args):
    print(args)

Register bar as a hook to be executed before calling foo

@foo.before(*args):
def bar(*args):
    print('before foo, args: ' + str(args))

When you call foo, bar is called before

foo(1, 2)

Expected output:

before foo, args: (1, 2)
(1, 2)

Class usage (python 3.x only)

You can use yaphs hooks inside classes:

class MyClass:
    @Hook
    def foo(self, *args)

When you register hooks, you just have to know that the first argument will be the object

c = MyClass()

@c.foo.after:
def bar(o, *args):
    print('after foo')
    print('object: ' + str(o))
    print('args: ' + str(args))

Project details


Release history Release notifications

This version

1.0

Download files

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

Files for yaphs, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size yaphs-1.0-py3-none-any.whl (2.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size yaphs-1.0.tar.gz (1.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page