interceptor-registry
Add pre/post/around interceptors on bound methods at runtime — without modifying the original class.
Full documentation at saemeon.github.io/interceptor-registry
Installation
pip install interceptor-registry
Quick Start
from contextlib import contextmanager
from interceptor_registry import add_interceptor, del_interceptor, del_interceptors
class Foo:
def bar(self):
print("inside method call")
return "result"
@staticmethod
def static_bar(x):
return x * 2
foo = Foo()
def print_before():
print("before")
@contextmanager
def around():
print("enter context")
try:
yield
finally:
print("exit context")
add_interceptor(foo, 'bar', print_before, callorder=-2)
add_interceptor(foo, 'bar', around, is_context_manager=True, callorder=-1)
foo.bar()
# before
# enter context
# inside method call
# exit context
# Works for instance methods, classmethods, staticmethods, async methods,
# generator methods, and async-generator methods.
add_interceptor(foo, 'static_bar', print_before, callorder=-1)
Use del_interceptor with the returned ID to remove a single interceptor,
or del_interceptors to clear all:
iid = add_interceptor(foo, 'bar', print_before, callorder=-1)
del_interceptor(foo, 'bar', iid)
del_interceptors(foo, 'bar')
Not supported
- Properties and other non-callable custom descriptors (raises
TypeErrorat registration). - Async hook functions —
async def/ async-generator hooks (raisesTypeErrorat registration). - Async context-manager hooks (
@asynccontextmanagerpassed withis_context_manager=True) — raisesTypeErrorwhen invoked. - Pickling of patched objects. Call
del_interceptorsbefore pickling, re-add after unpickling.
License
MIT
Metadata
Release files for interceptor-registry 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| interceptor_registry-0.0.2.tar.gz | 121.5 kB | With provenance | Details for interceptor_registry-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| interceptor_registry-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for interceptor_registry-0.0.2-py3-none-any.whl |
Total release size: 134.5 kB
Release files / interceptor_registry-0.0.2.tar.gz
| Download URL | interceptor_registry-0.0.2.tar.gz |
|---|---|
| Size | 121.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f43cea09cdab58f95149001163197a0cd8150ad186ac93347f41b4e1f005dac5
|
|
BLAKE2b-256 checksum How to use checksums |
05b70df8123366fd8856e187b775f870b645448dcdcd10be4a2935fe15655e61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency logRelease files / interceptor_registry-0.0.2-py3-none-any.whl
| Download URL | interceptor_registry-0.0.2-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c74554bf00039161cf584653793b86052e81794e224c523bcc9133edbffbf0eb
|
|
BLAKE2b-256 checksum How to use checksums |
86450235e049672ffbd6bf70157731d47658547c424934caad6a52f2d31c98ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency logSecurity for interceptor-registry 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for interceptor_registry-0.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.