Skip to main content

PyPI Python License Ruff uv ty prek

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 TypeError at registration).
  • Async hook functions — async def / async-generator hooks (raises TypeError at registration).
  • Async context-manager hooks (@asynccontextmanager passed with is_context_manager=True) — raises TypeError when invoked.
  • Pickling of patched objects. Call del_interceptors before 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)

Source distribution for interceptor-registry 0.0.2
File Size Uploaded
interceptor_registry-0.0.2.tar.gz 121.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for interceptor-registry 0.0.2
File Interpreter ABI Platform
interceptor_registry-0.0.2-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page