zope.hookable
Zope hookable
What it is and what it does
zope.hookable is a utility for creating callable objects that support dynamic replacement via a sethook method. When you decorate a function with @hookable or wrap it, all code that calls it—including code that imported it before the hook was set—will immediately see the replacement implementation. This pattern is useful in frameworks and plugin systems where you want to provide default behavior but allow later customization without requiring callers to be aware of the change.
The package has no runtime dependencies and provides a thin, efficient layer over Python's callable protocol. It's part of the Zope ecosystem but can be used standalone. It supports Python 3.10 through 3.14 and both CPython and PyPy, with precompiled wheels available for common platforms.
Use it for:
- Framework authors providing default implementations that plugins can override without modifying call sites.
- Testing scenarios where you need to inject mock or stub implementations into code that has already imported a function.
- Loose coupling in event-driven systems where handlers can be swapped at runtime.
- Configuration-driven behavior where the active implementation changes based on runtime state or settings.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
zope.hookable provides a mechanism to create callable objects that can be dynamically replaced at runtime, allowing all references to them to see the change immediately.
Yes, if you need dynamic function replacement with global visibility. The package is stable, actively maintained, has no known vulnerabilities, and carries minimal overhead. The main caveat is verifying that ZPL-2.1 is compatible with your project's licensing model, and confirming that the license treatment uncertainty does not create compliance risk for your use case.
Install
zope-hookable on PyPI
pip
pip install zope-hookableuv
uv add zope-hookablepoetry
poetry add zope-hookableInstalling zope.hookable
Before you install
Medium install friction due to compiled wheels for multiple Python versions and platforms. Package is actively maintained with recent releases and no known vulnerabilities.
License in practice
Licensed under ZPL-2.1 (Zope Public License); license treatment is unclear, so review the actual license terms before use in proprietary or restricted contexts.
Quickstart
from zope.hookable import hookable
@hookable
def my_function():
return "default"
my_function.sethook(lambda: "replaced")
print(my_function()) # prints "replaced"
Requires Python 3.10 or later.
Verify before relying
- Whether the ZPL-2.1 license is compatible with your project's licensing requirements.
- Performance characteristics and overhead of the hookable mechanism compared to direct function calls.
- Whether PyPy support is actively tested or only nominally declared.
Package facts
| License | ZPL-2.1 (unclear) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 269 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,008,039/month — #4,520 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: zope_hookable-8.2-cp310-cp310-macosx_10_9_x86_64.whl; zope_hookable-8.2-cp310-cp310-macosx_11_0_arm64.whl; zope_hookable-8.2-cp310-cp310-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl; zope_hookable-8.2-cp310-cp310-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl; zope_hookable-8.2-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; zope_hookable-8.2-cp310-cp310-win_amd64.whl; zope_hookable-8.2-cp311-cp311-macosx_10_9_x86_64.whl; zope_hookable-8.2-cp311-cp311-macosx_11_0_arm64.whl; zope_hookable-8.2-cp311-cp311-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl; zope_hookable-8.2-cp311-cp311-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl; zope_hookable-8.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; zope_hookable-8.2-cp311-cp311-win_amd64.whl; zope_hookable-8.2-cp312-cp312-macosx_10_9_x86_64.whl; zope_hookable-8.2-cp312-cp312-macosx_11_0_arm64.whl; zope_hookable-8.2-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl; zope_hookable-8.2-cp312-cp312-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl; zope_hookable-8.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; zope_hookable-8.2-cp312-cp312-win_amd64.whl; zope_hookable-8.2-cp313-cp313-macosx_10_9_x86_64.whl; zope_hookable-8.2-cp313-cp313-macosx_11_0_arm64.whl
Keywords: zope, function, hook, replacement, loose, coupled
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
zope.annotationStores additional metadata on objects without…
unclear · top 15,000 on PyPI
zope.lifecycleeventDefines event objects and API functions for…
unclear · top 15,000 on PyPI
xmodLets a module behave like a callable object or…
permissive · top 5,000 on PyPI
zope.componentImplements the core Zope Component Architecture…
unclear · top 5,000 on PyPI
zope.viewletzope.viewlet provides a pluggable framework for…
unclear · top 15,000 on PyPI
zope.securityProvides a generic security framework for…
unclear · top 15,000 on PyPI
zope.ptresourceProvides a resource class that processes Zope…
unclear · top 15,000 on PyPI
zope.configurationZope.configuration provides an extensible…
unclear · top 5,000 on PyPI
zope.globalrequestProvides a function to retrieve the currently…
unclear · top 15,000 on PyPI
DocumentTemplateDocumentTemplate implements the Document…
unclear · top 15,000 on PyPI