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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 17.9MB
glibcpy 3.10–3.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.fixUpgrade 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.fixSet 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.fixThoroughly 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.