pyrewind: Python Execution Forensics, Time-Travel Debugging & Automated Diagnostics
pyrewind is a zero-dependency Python execution forensics, time-travel debugging, and automated diagnostic library. It records the step-by-step lifecycle of Python functions, freezes local variable mutations across execution steps, provides an interactive terminal time-travel scrubber, and automatically identifies root causes and anomalies when functions crash or produce invalid states.
Key Capabilities
- Interactive Terminal TUI Scrubber (
pyrewind tui):- Step forward and backward through execution history using standard keyboard navigation.
- Dual-pane layout: source code highlighting on the left, local variable mutation table on the right.
- Jump directly to exceptions, checkpoints, and performance bottlenecks.
- Automated Root-Cause Diagnostic & Anomaly Engine (
pyrewind diagnose/pyrewind.diagnostics):RootCauseExplainer: Backward data-flow dependency analysis from exceptions or return values to pinpoint the originating line and mutated variable.AnomalyDetector: Identifies unexpectedNonetransitions,NaN/Infarithmetic bugs, runaway collection growth inside loops, and timing execution spikes.
- Assisted Replay & Parameter Overrides (
replay):- Fluent replay builder for rerunning functions with modified arguments or step overrides.
- Trace Analysis & Comparison (
TraceInspector&TraceComparison):- Performance hotspot identification, execution diffing between multiple runs, and variable lifecycle inspection.
- Zero External Runtime Dependencies:
- Implemented entirely with the Python Standard Library.
Interactive Terminal TUI Showcase
The interactive terminal scrubber enables developers to inspect execution states without external GUI or web dependencies:
1. Loop Iteration & Variable Mutation Tracking
Live execution view showing active source code line highlight alongside the mutated local variables table:
2. Initial Step Allocation & Scope Inspection
Initial execution step displaying captured function arguments and variable initialization states:
Installation
# Install from PyPI
pip install pyrewind
# Or install from source in editable mode
git clone https://github.com/adityarajIITj/PYREWIND.git
cd PYREWIND
pip install -e .
Quickstart Guide
1. Tracing Function Execution
from pyrewind import rewindable
@rewindable
def calculate_tax(gross_income, deduction_rate):
deductions = gross_income * deduction_rate
taxable_amount = gross_income - deductions
tax = taxable_amount * 0.20
return tax
# Run with trace recording
tax, trace = calculate_tax.run(100_000, 0.15)
print(f"Tax: ${tax}")
print(f"Recorded Steps: {len(trace.steps)}")
# Inspect step 0 locals
print(trace.at(0).locals())
2. Interactive Terminal Time-Travel Scrubber (TUI)
Scrub through any recorded trace interactively in your terminal:
from pyrewind import rewindable, launch_tui
@rewindable
def complex_algorithm():
data = []
for i in range(5):
data.append(i * 10)
return sum(data)
complex_algorithm.run()
launch_tui(complex_algorithm.last_trace)
Or from the CLI:
pyrewind tui trace.json
Keybindings:
[<- / h]: Step Backward[-> / l]: Step Forward[0 / Home]: Jump to First Step[$ / End]: Jump to Last Step[e]: Jump directly to Exception[d]: View Full Diagnostic Report[q]: Quit Scrubber
3. Automated Root-Cause Diagnostics & Anomaly Detection
from pyrewind import rewindable, diagnose_trace
@rewindable
def process_pipeline(val, rate):
offset = rate - 0.05
divisor = offset + 1.0 # Divisor becomes 0 if rate == -0.95
return (val * 1.5) / divisor
try:
process_pipeline.run(1000, -0.95)
except ZeroDivisionError:
pass
# Generate automated root cause report
report = diagnose_trace(process_pipeline.last_trace)
print(report)
Sample Diagnostic Output:
=== PyRewind Automated Diagnostic Report ===
Function: process_pipeline (__main__)
Total Steps: 5 | Trace ID: 2a7804a2
------------------------------------------------------------
[!] ROOT CAUSE DIAGNOSIS: ZeroDivisionError
Message: division by zero
Failure Point: Step #4 (line 7)
Root Cause Point: Step #3 (line 6)
Explanation: ZeroDivisionError occurred at line 7 because variable 'divisor' was evaluated as 0. Variable 'divisor' was assigned 0 at Step #3 (line 6).
Remediation: Add a defensive check: 'if divisor == 0: ...' or check the assignment logic at line 6.
Tainted Variables:
- divisor: introduced at Step #3 (line 6) -> Assigned 0/0.0 at Step #3 (line 6), subsequently used as divisor.
[*] DETECTED ANOMALIES (0 found):
No data-flow or arithmetic anomalies detected.
============================================================
CLI Command Reference
| Command | Usage | Description |
|---|---|---|
tui |
pyrewind tui <trace.json> |
Launch interactive Terminal Time-Travel Scrubber. |
diagnose |
pyrewind diagnose <trace.json> [--var <name>] |
Run automated root-cause & anomaly diagnostics. |
inspect |
pyrewind inspect <trace.json> [-v] |
Print statistical timing and variable summaries. |
diff |
pyrewind diff <trace1.json> <trace2.json> |
Compare two execution traces and identify divergences. |
export |
pyrewind export <trace.json> -o out.html -f html |
Export trace to HTML, CSV, or JSON. |
Automated Test Suite
pytest tests -v
All 59 unit tests pass in under 0.5s.
License
Distributed under the MIT License. See LICENSE for details.
Author
Aditya Raj
Indian Institute of Technology Jodhpur (IIT Jodhpur)
Email: b25bs1020@iitj.ac.in
GitHub: @adityarajIITj
Metadata
Release files for pyrewind-dev 0.3.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 |
|---|---|---|---|---|
| pyrewind_dev-0.3.0.tar.gz | 146.4 kB | Without provenance | Details for pyrewind_dev-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyrewind_dev-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pyrewind_dev-0.3.0-py3-none-any.whl |
Total release size: 211.7 kB
Release files / pyrewind_dev-0.3.0.tar.gz
| Download URL | pyrewind_dev-0.3.0.tar.gz |
|---|---|
| Size | 146.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68b08512810ae9791e6c0abff6b40e52aa00e043d3dd84d0bef62d9af69a6e52
|
|
BLAKE2b-256 checksum How to use checksums |
44ec6cbe0ae9d9f5e140775de05b0e81f2058a8ec87b03a658095a0182e92429
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / pyrewind_dev-0.3.0-py3-none-any.whl
| Download URL | pyrewind_dev-0.3.0-py3-none-any.whl |
|---|---|
| Size | 65.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42cf6157be832e82b15f150c9c86e4296f582729d574a80479b010e79e2653cf
|
|
BLAKE2b-256 checksum How to use checksums |
c8ebcba484f73303b9e96c0079bebc88a9c7834e1ed7505cba6220f7610c848b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for pyrewind-dev 0.3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.