Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

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

Project Description

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 hooks and register callbacks.

from hookery import HookRegistry

hooks = HookRegistry()

# It doesn't matter where you put the hook instance.
# We set it as hooks attribute to keep things tidy.
hooks.user_added = hooks.create_hook('user_added')

_users = {}

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

def notify_me():
    print('A new user has been added!')

def say_hi(username):
    print('Hi, {}'.format(username))
>>> create_user('Bob', password='secret')
A new user has been added!
Hi, Bob

Release History

This version
History Node


Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting