AutoWrapper
AutoWrapper is a small Python helper for building wrapper/proxy objects around another object's methods.
It lets a wrapper class expose selected methods from a target object and optionally route method calls through pre/post/exception hooks. This is useful for lightweight instrumentation such as logging, tracing, metrics, access checks, or debugging wrappers.
Current status
This project is still small and intentionally direct: one implementation module, AutoWrapper.py, a lowercase compatibility import module, packaging metadata, and a unittest test suite.
Implemented behavior:
- Wrap methods from a target object onto a wrapper instance.
- Call target-bound methods so target instance state is preserved.
- Support optional hints for selecting which methods to proxy and wrap.
- Support no-hints mode, which proxies and wraps all public discovered methods.
- Discover inherited instance methods, static methods, and class methods.
- Skip private/dunder methods by default, with explicit hint opt-in.
- Preserve useful method metadata for wrapped methods via
functools.wraps(). - Provide pre, post, and exception hooks with method context.
- Reject proxied method names that would overwrite wrapper attributes or methods.
- Provide typed public methods and prefer the snake_case
get_methods_to_wrap()discovery API while preservinggetMethods2Wrap()compatibility.
Basic usage
from autowrapper import AutoWrapper
class Example:
def __init__(self):
self.count = 0
def increment(self, amount=1):
self.count += amount
return self.count
class WrappedExample(AutoWrapper):
def __init__(self, target):
self.events = []
self.build_wrapper(
target,
hints={"increment": {"proxy": True, "wrap": True}},
)
def _pre_method_hook(self, method_name, method, args, kwargs):
self.events.append(("pre", method_name, args, kwargs))
def _post_method_hook(self, method_name, method, args, kwargs, result):
self.events.append(("post", method_name, result))
def _exception_method_hook(self, method_name, method, args, kwargs, exc):
self.events.append(("exception", method_name, exc))
target = Example()
wrapper = WrappedExample(target)
assert wrapper.increment(amount=2) == 2
assert target.count == 2
assert wrapper.events == [
("pre", "increment", (), {"amount": 2}),
("post", "increment", 2),
]
Scope: object methods, not standalone functions
AutoWrapper is intentionally scoped to wrapping methods discovered from a target object. It supports instance methods, inherited methods, static methods, and class methods on that target object's class.
Standalone/free functions are out of scope for now. If you need to wrap a free function, use a normal decorator directly or place the function behind a small object method before using AutoWrapper.
Method discovery API
The preferred public discovery helper is:
AutoWrapper.get_methods_to_wrap(TargetClass, hints=None)
The original spelling remains available for compatibility:
AutoWrapper.getMethods2Wrap(TargetClass, hints=None)
Hint semantics
build_wrapper(target, hints=...) accepts a dictionary keyed by method name.
Supported keys:
proxy: expose this method on the wrapper instance.wrap: route the proxied method through the hook methods.
Behavior:
hints is None: proxy and wrap every public discovered instance, static, and class method.proxy: True: expose the method on the wrapper.proxyabsent or false: do not expose the method, even ifwrap: True.wrap: True: call_pre_method_hook()before the target method and_post_method_hook()after it succeeds.wrapabsent or false: expose the target-bound method directly without hooks.- Methods absent from a supplied
hintsdictionary are not proxied. - Static methods and class methods are supported and can be proxied/wrapped like instance methods.
- Private methods whose names begin with
_are skipped by default, but can be explicitly proxied with hints. - Proxied method names that collide with existing wrapper attributes or methods raise
AttributeError.
Hook signatures
Override these methods in your wrapper subclass when you need behavior around wrapped calls:
def _pre_method_hook(self, method_name, method, args, kwargs):
pass
def _post_method_hook(self, method_name, method, args, kwargs, result):
pass
def _exception_method_hook(self, method_name, method, args, kwargs, exc):
pass
Exceptions raised by wrapped target methods call _exception_method_hook() and then propagate unchanged.
Installation
Once published to PyPI, install with:
python -m pip install blakemere-autowrapper
For local development from a clean checkout:
python -m pip install -e .
The PyPI distribution name is blakemere-autowrapper. The preferred import path is lowercase:
from autowrapper import AutoWrapper
The original import path remains available for compatibility:
from AutoWrapper import AutoWrapper
Running tests
This project currently uses the Python standard-library unittest framework, so no test dependency installation is required.
Supported Python versions currently track the CI matrix: Python 3.9 through 3.13.
From a clean checkout, run:
python -m unittest discover -s tests -v
You can also run the inline example in the implementation module:
python AutoWrapper.py
Repository layout
AutoWrapper.py # implementation and tiny inline example
autowrapper.py # lowercase import compatibility module
pyproject.toml # packaging metadata
__init__.py # placeholder package marker
tests/test_autowrapper.py # unittest coverage
BACKLOG.md # project improvement backlog
Packaging note
pyproject.toml packages both modules:
autowrapper: preferred lowercase import path.AutoWrapper: original compatibility import path.
The project uses modern SPDX license metadata and explicitly includes the license file in built distributions:
license = "MIT"
license-files = ["LICENSE"]
The build backend requires setuptools>=77.0.3, which provides the PEP 639/SPDX license metadata support used here. The built wheel includes the LICENSE file under .dist-info/licenses/.
License
MIT. See LICENSE.
Metadata
Release files for blakemere-autowrapper 0.1.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 |
|---|---|---|---|---|
| blakemere_autowrapper-0.1.2.tar.gz | 8.3 kB | With provenance | Details for blakemere_autowrapper-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| blakemere_autowrapper-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for blakemere_autowrapper-0.1.2-py3-none-any.whl |
Total release size: 15.0 kB
Release files / blakemere_autowrapper-0.1.2.tar.gz
| Download URL | blakemere_autowrapper-0.1.2.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ae487d02efb2a01615c6277675629989c51e9791684cec3417d2d305656073e
|
|
BLAKE2b-256 checksum How to use checksums |
4a366c99cd11762a57b7c70c27b32322aa4cbe08bb26371f907bed7cfbeeb04c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 Jun 12, 2026.
Transparency logRelease files / blakemere_autowrapper-0.1.2-py3-none-any.whl
| Download URL | blakemere_autowrapper-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c739ad9834012066f28eb0614a0ab129cfbebd16e7e956666fe07d6c377365ca
|
|
BLAKE2b-256 checksum How to use checksums |
2964ce547dc7ce8bb797b3859a398f197d4ba9382c96237ab148e190422f42c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 Jun 12, 2026.
Transparency logSecurity for blakemere-autowrapper 0.1.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 blakemere_autowrapper-0.1.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 Jun 12, 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.