Skip to main content

Python Hookups

A generic, type-safe hook and signal system for Python projects. It supports automatic discovery of extension points (hooks) and event-driven signals with both synchronous and asynchronous support.

Features

  • Type-safe Hooks: Register functions with specific names and execution orders.
  • Professional Signals: Standalone signal implementation with sync and async sending.
  • Automatic Discovery: Automatically finds and imports hookups submodules in your packages.
  • CLI Support: Inspect registered hooks and signals from the command line.
  • Modern Python: Built with Python 3.12+, Pydantic validation, and uv package management.

Installation

# Using uv (recommended)
uv add python-hookups

# Using pip
pip install python-hookups

Usage

1. Hook System

Hooks are used when you want to allow other parts of your application (or plugins) to provide values or execute logic at specific points.

Registration

from hookups import register_hookup

@register_hookup("UI_MENU_HOOKUP", order=10)
def my_menu_item():
    return {"label": "My Plugin", "url": "/plugin"}

Discovery and Execution

from hookups import set_scan_paths, discover_hookups, get_hookups

# 1. Configure where to look for 'hookups' submodules
set_scan_paths(["my_app.plugins", "my_app.extensions"])

# 2. Discover and load all hookups
discover_hookups()

# 3. Get and execute hooks
hooks = get_hookups("UI_MENU_HOOKUP")
for hook in hooks:
    result = hook()
    print(result)

2. Signal System

Signals are used for "fire-and-forget" events. They support both synchronous and asynchronous receivers.

Definition

from hookups import Signal

user_registered = Signal(name="user_registered")

Connection

from hookups import receiver

@receiver(user_registered)
async def send_welcome_email(sender, username, **kwargs):
    print(f"Sending welcome email to {username}...")

@receiver(user_registered)
def log_registration(sender, username, **kwargs):
    print(f"Audit log: {username} joined.")

Sending

# Asynchronous sending (handles both sync and async receivers)
await user_registered.send_async(sender=None, username="Alice")

# Synchronous sending (for sync-only contexts)
user_registered.send(sender=None, username="Alice")

# Robust sending (continues even if receivers raise exceptions)
await user_registered.send_async_robust(sender=None, username="Alice")

CLI Usage

You can list all registered hooks and signals using the built-in CLI.

# List all registered hooks
python main.py --list hooks

# List all registered signals and their receivers
python main.py --list signals

Example Project

Check out the example/ directory for a complete working demonstration of how to structure a project with plugins using python-hookups.

uv run python example/app.py

Development

# Run tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=hookups

Metadata

Release files for python-hookups 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-hookups 0.1.2
File Size Uploaded
python_hookups-0.1.2.tar.gz 34.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-hookups 0.1.2
File Interpreter ABI Platform
python_hookups-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 42.3 kB

Release files / python_hookups-0.1.2.tar.gz

Download URL python_hookups-0.1.2.tar.gz
Size 34.7 kB
Tags Source
SHA-256 checksum
How to use checksums
18c2b5c736453cfcdb151b65a0f119e10cdbd073a35de64eb33ba6b9361c5f1a
BLAKE2b-256 checksum
How to use checksums
c86fe2ba10c023f59c816d2beae2df2aa8d6631d4bf3306d048393cce850916e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / python_hookups-0.1.2-py3-none-any.whl

Download URL python_hookups-0.1.2-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b8e9b85284534e4733762689f1b56086441027f4d0e78e02325ee49ce0e5b05
BLAKE2b-256 checksum
How to use checksums
f1051e44b7f31dcea031c39606693896e9a99cc57127675014a7d41b5f7c75b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page