skillfed

zope.hookable

Zope hookable

zope-hookable v8.2 1.0M downloads/30d#4,520 on PyPI3
License unclear ZPL-2.1 Active released

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-hookable

uv

uv add zope-hookable

poetry

poetry add zope-hookable

Installing 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

Development Status :: 5 - Production/StableFramework :: Zope :: 3Intended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

dynamic function replacementruntime hook mechanismcallable replacement patternloose coupling callbackszope hookable objects
plugin-patternruntime-replacement

More Software Development packages