Registry / serialization / zope-hookable

zope-hookable

JSON →
library8.3pypypi✓ verified 20d ago

Zope Hookable is a Python package that facilitates the efficient creation of "hookable" objects. These are callable objects designed to be optionally replaced at runtime. This allows developers to define a default behavior for a function and then dynamically change its implementation, affecting all users of that function, even those who imported it. The current version is 8.2 and it is part of the Zope ecosystem, which generally follows semantic versioning with minor releases every 2-6 months and major releases every 2-3 years, though `zope.hookable` itself has a less frequent major release cycle.

pip install zope-hookable
INSTALL
IMPORT
SIG · ZOPE-HOOKABLE
Z
zope-hookable
serializationpythonv8.3
Install
1.5s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.008s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

hookable
from zope.hookable import hookable

This example demonstrates how to define a hookable function, dynamically replace its implementation using `sethook`, and then revert to the original default implementation with `reset()`.

from zope.hookable import hookable # 1. Define a default implementation for a function def _my_default_function(name): return f"Hello, {name} (default) via id {id(_my_default_function)}" # 2. Make it hookable my_hookable_function = hookable(_my_default_function) # 3. Use the hookable function - it calls the default implementation print(f"Initial call: {my_hookable_function('World')}") # 4. Define a new implementation def _my_custom_function(name): return f"Greetings, {name} (custom) via id {id(_my_custom_function)}" # 5. Set the hook to the new implementation my_hookable_function.sethook(_my_custom_function) # 6. The function now uses the new implementation print(f"After hook: {my_hookable_function('User')}") # 7. Define another implementation def _my_another_function(name, greeting='Hi'): return f"{greeting}, {name} (another) via id {id(_my_another_function)}" # 8. Set another hook, passing additional arguments if necessary for the new hook's signature my_hookable_function.sethook(_my_another_function, 'Hola') print(f"Another hook: {my_hookable_function('Friend')}") # 9. Reset to the original default implementation my_hookable_function.reset() print(f"After reset: {my_hookable_function('Again')}")
Debug
Known issues
breakingOlder Python versions are no longer supported. `zope.hookable` has progressively dropped support for EOL Python versions. Version 8.2 requires Python 3.10 or newer. Ensure your environment meets the `requires_python` specification to avoid compatibility errors.
fix
Upgrade to Python 3.10 or a newer compatible version (e.g., Python 3.11, 3.12, 3.13, 3.14 for `zope.hookable` 8.2).
affects: < 8.2
gotcha`zope.hookable` typically includes a C extension for performance. In environments where C extensions are problematic or for debugging purposes, you can force the use of a pure-Python implementation by setting the `PURE_PYTHON` environment variable to a truthy value before installing or running.
fix
Set the environment variable: `export PURE_PYTHON=1` (or `set PURE_PYTHON=1` on Windows) before running `pip install zope-hookable` or executing your application.
affects: All versions with C extensions
gotchaUsing `zope.hookable` involves modifying global state, as changing a hook's implementation affects all parts of your application that reference that hookable object. This can lead to unexpected side effects or difficult-to-trace bugs if not managed carefully, especially in complex or multi-threaded applications. Ensure proper testing and understand the implications of runtime code replacement.
fix
Thoroughly test changes made via `sethook` in all relevant execution paths. Consider using context managers or dependency injection patterns for more controlled dynamic behavior where global state changes might be risky.
affects: All versions
Upgrade
Version history
8.3latest on PyPI · released Aug 20, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
32
OpenAI (training)
1
Resources
zope-hookable — pip install zope-hookable · libregistry