hookery 0.3.2
pip install hookery==0.3.2
Newer version available (5.0.1)
Released:
Trivial, primitive, naive, and optimistic hook registry in Python
Navigation
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: MIT License (MIT)
- Author: Jazeps Basko
Classifiers
- Development Status
- Intended Audience
- License
- Programming Language
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
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: MIT License (MIT)
- Author: Jazeps Basko
Classifiers
- Development Status
- Intended Audience
- License
- Programming Language
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file hookery-0.3.2.tar.gz
.
File metadata
- Download URL: hookery-0.3.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e338b8e5d49e9d6fbf80f2b63f4f50a14476c04c46228598a38d0437c5d12fe |
|
MD5 | 5b8418c7cfe0ad0e668c713ad21c5a63 |
|
BLAKE2b-256 | 96900eef3c1a002a3f31c4825aa27fb7bb463ad5d94565f5ff22d9c519788687 |