dowhen
dowhen makes instrumentation (monkeypatch) super intuitive and maintainable
with minimal overhead!
You can execute arbitrary code at specific points of your application, third-party libraries or stdlib in order to
- debug your program
- change the original behavior of the libraries
- monitor your application
Installation
pip install dowhen
Usage
The core idea behind dowhen is to do a callback on a trigger. The
trigger is specified with when and there are 3 kinds of callbacks.
do
do executes an arbitrary piece of code.
from dowhen import do
def f(x):
x += 100
# Let's change the value of x before return
return x
# do("x = 1") is the callback
# when(f, "return x") is the trigger
# This is equivalent to:
# handler = when(f, "return x").do("x = 1")
handler = do("x = 1").when(f, "return x")
# x = 1 is executed before "return x"
assert f(0) == 1
# You can remove the handler
handler.remove()
assert f(0) == 100
bp
bp sets a breakpoint and brings up pdb.
from dowhen import bp
# bp() is another callback that brings up pdb
handler = bp().when(f, "return x")
# This will enter pdb
f(0)
# You can temporarily disable the handler
# handler.enable() will enable it again
handler.disable()
goto
goto changes the next line to execute.
from dowhen import goto
# This will skip the line of `x += 100`
# The handler will be removed after the with context
with goto("return x").when(f, "x += 100"):
assert f(0) == 0
callback chains
from dowhen import when
# You can chain callbacks and they'll run in order at the trigger
# You don't need to store the handler if you don't use it
when(f, "x += 100").goto("return x").do("x = 42")
assert f(0) == 42
See detailed documentation at https://dowhen.readthedocs.io/
License
Copyright 2025 Tian Gao.
Distributed under the terms of the Apache 2.0 license.
Metadata
Release files for dowhen 0.1.0
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 |
|---|---|---|---|---|
| dowhen-0.1.0.tar.gz | 21.4 kB | With provenance | Details for dowhen-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dowhen-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for dowhen-0.1.0-py3-none-any.whl |
Total release size: 40.5 kB
Release files / dowhen-0.1.0.tar.gz
| Download URL | dowhen-0.1.0.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
418804e52e715fd61f362c285eb0e8023819569fae85b592025d707246a1aea9
|
|
BLAKE2b-256 checksum How to use checksums |
381961042b0a86170158940dd9aba60ce485922a8101d762b6b50b7cd65e91d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 26, 2025.
Transparency logRelease files / dowhen-0.1.0-py3-none-any.whl
| Download URL | dowhen-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
723a39b838ac15a2d6d3a40bfcc21b672a6f760354a00a373c53c6b23de4cfb5
|
|
BLAKE2b-256 checksum How to use checksums |
1b5afaf4ca6fe29f3cfcc7c730245e47112d236e8f3bd3b23666975c3ddc287f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 26, 2025.
Transparency logSecurity for dowhen 0.1.0
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for dowhen-0.1.0.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 26, 2025.
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.