wrapture: The New Python Monkey-Patching Tool That Unifies Testing and Observability

wrapture unifies Python test mocking and production observability under one runtime instrumentation framework.
wrapture is a Python monkey-patching library by Graham Dumpleton that unifies testing (mocking/stubbing) and observability (call tracing, performance profiling) under a single API. Its standout feature is zero-code instrumentation via TOML files — no Python source changes required. The companion wrapture-instrumentation package provides pre-built support for Django, FastAPI, Flask, SQLAlchemy, httpx, and dozens more, with trace data exportable to OpenTelemetry. Still in alpha, but already highly usable. Simon Willison calls it a "Swiss Army knife" for testing, debugging, and distributed tracing.
Graham Dumpleton's new monkey patching library wrapture is quietly becoming an essential tool for Python developers. Surprisingly, it hasn't attracted much community buzz yet — but as Simon Willison put it, it deserves a lot more attention.
What Problem Does wrapture Actually Solve?
Monkey patching isn't a new concept in Python — unittest.mock has long been a standard choice. What makes wrapture stand out is that it serves two use cases that are typically handled separately: testing and observability (think New Relic-style call tracing).
This design means developers can use the same toolset to both swap out and verify method calls in test environments, and record real runtime behavior in production or debugging contexts. Graham Dumpleton has deep roots in projects like WSGI, mod_wsgi, and the New Relic Python Agent — wrapture can be seen as the culmination of years of experience in function wrapping and runtime instrumentation.

Monkey patching is a technique for dynamically replacing or modifying the behavior of modules, classes, or functions at runtime — without touching the original source code. Python's dynamic nature makes this straightforward. In testing, monkey patching is commonly used to replace external dependencies (like database calls or HTTP requests) with controlled mock objects for isolated testing. In observability, it's used to inject timing, logging, or tracing logic before and after function calls without invasive changes to business logic — which is exactly how APM tools like New Relic and Datadog work under the hood. The two scenarios share nearly identical technical mechanisms, but historically tools focused on one or the other. wrapture unifies both under a single API, which is its fundamental distinction from unittest.mock.
A Content-Dense Tutorial Lineup
Since its initial release on August 31st, Graham has been publishing new tutorials almost daily — a release cadence that itself speaks to the library's breadth. Topics covered so far include:
Testing
- Unit Testing: Doing the kinds of things you'd do with
unittest.mock. - Recording Calls: Recording method calls as a timeline, then processing and displaying them as a tree.
- Phased Behaviour: Scheduling patched methods to change behavior across multiple calls.
- Beyond Callables: Monkey-patching attributes, dictionaries, and generators.
Tracing and Observability
- Live Tracing: Tracing a running application to understand exactly how it works.
- Zero-Code Tracing: Configuring tracing in a standalone TOML file without modifying any Python code.
- Finding Slow Code: Recording timing for individual calls and aggregated across multiple calls.
- OpenTelemetry Export: Exporting trace data to OpenTelemetry.
Zero-Code Instrumentation: The Standout Feature
wrapture's most compelling capability is the ability to configure and experiment with it without modifying a single line of Python code — just write a TOML file. This is enormously valuable for teams that want to quickly evaluate a tool or avoid touching an existing codebase.
Going further, Graham has also published a separate wrapture-instrumentation package with pre-built instrumentation support for a wide range of popular libraries:
- Web frameworks:
django,fastapi,flask,starlette - HTTP clients:
requests,httpx,urllib3,http.client,aiohttp.client - Servers:
uvicorn,werkzeug.serving,wsgiref.simple_server - Databases:
sqlalchemy,sqlite3 - Others:
grpc,jinja2,xmlrpc, and more
Take Tracing Flask with wrapture as an example — developers can instrument a Flask application directly using this package without manually wrapping every function. This kind of out-of-the-box ecosystem support is a key indicator of whether an observability tool is actually practical.
OpenTelemetry (OTel) is an open standard led by the CNCF, designed to unify the collection and export of traces, metrics, and logs across distributed systems. Its core value is vendor neutrality — once you've instrumented your application to the OTel spec, you're free to export data to Jaeger, Zipkin, Grafana Tempo, Datadog, or any compatible backend without writing platform-specific integration code. wrapture's support for exporting to OpenTelemetry means it's not a closed proprietary observability solution — it's a standardized tool that integrates seamlessly with existing monitoring infrastructure, which dramatically lowers the adoption cost for teams already running OTel in production.
Getting Started and Current Status
Beyond the documentation and tutorials, Graham has also prepared an interactive workshop in the form of JupyterLab notebooks, letting developers learn through hands-on practice.
It's worth noting that wrapture is still in alpha. That said, based on Simon Willison's hands-on assessment, it's already quite usable — particularly the low-friction TOML-based configuration that lets you try things out without touching source code, which significantly reduces the risk of early adoption.
Why It's Worth Paying Attention to Now
Simon Willison described wrapture as a "Swiss Army knife" toolkit: once you've learned it, you'll find yourself reaching for it across a wide variety of problems for years to come. That framing captures wrapture's core positioning — it's not a narrow library that solves one specific pain point, but a general-purpose runtime instrumentation framework that spans testing, debugging, performance profiling, and distributed tracing.
For engineers who work extensively with Python, unifying test mocking and production observability under a single mental model and API is itself a meaningful reduction in cognitive overhead. The fact that wrapture hasn't gotten much attention yet is precisely what makes now a good time to get ahead of the curve.
Related articles

Catalyst: A Vision for an Enzyme-Like Testing Framework for AI Agents
A developer shared Catalyst on Reddit, an Enzyme-inspired framework for AI Agents, exploring why agents need observable, testable dev tools and the design philosophy behind them.

The Real Capability of AI Coding Agents: Best Models Complete Only 35% of Feature Development Tasks
The 'Agents on Rails' benchmark finds top AI models complete only 35% of feature development tasks. What this means for coding agents and developer teams.

How to Prevent Duplicate Refunds After an AI Agent Crashes: CellaFlow's Durable Execution Approach
How can AI agents avoid duplicate refunds after a crash without deadlocking workflows? CellaFlow uses durable execution, shared work identity, leases, and fencing to solve safety and liveness in multi-agent systems.