Skip to main content

Trivial, primitive, naive, and optimistic hook registry in Python

Project description

pip install hookery

It’s really simple. There are some events in the lifetime of your simple Python application that you want to hook into, and you don’t want to be overriding methods or writing conditional code to do that. What you do is you introduce events and register hooks.

from hookery import HookRegistry

hooks = HookRegistry()

# It doesn't matter where you put the event instance.
# We set it as a hooks attribute just to keep things tidy
# in this module.
hooks.user_added = hooks.register_event('user_added')

# A dummy user storage
_users = {}


def create_user(username, password):
    _users[username] = password
    hooks.user_added.trigger(username=username)


@hooks.user_added
def notify_me():
    print('A new user has been added!')


@hooks.user_added
def say_hi(username):
    print('Hi, {}'.format(username))

Now you can create some users and let all listeners know about it:

>>> create_user('Bob', password='secret')
A new user has been added!
Hi, Bob

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

hookery-0.3.0.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file hookery-0.3.0.tar.gz.

File metadata

  • Download URL: hookery-0.3.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hookery-0.3.0.tar.gz
Algorithm Hash digest
SHA256 89395b78516339d67a928f302aa92f49cf15c659f22682ede9ea14ebd186bcce
MD5 0fbc388296fc9d143b54273c9527487e
BLAKE2b-256 fb24b9a58c7ef557fb5aa64de01e3c7a26f2d67d5d665555db0ec2a0c09d1219

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