A lightweight line-by-line Python execution tracer
Project description
Steptrace
A lightweight Python execution tracer that records line-by-line execution, call stack, runtime per step, and local/global variables — all filtered to your workspace for clean, readable logs.
Designed for debugging, learning, and understanding program flow.
Features
- 🔍 Line-by-line execution tracing
- 🧵 Call stack reconstruction
- ⏱ Runtime per step (milliseconds)
- 📦 Local and global variable inspection
- 🚫 Automatically ignores:
- Built-in modules
site-packages- Non-workspace files
- 🗂 Auto-incrementing log files (no overwrites)
- 🧼 Safe cleanup of
sys.settrace - 🧩 Supports context manager and decorator usage
Installation
pip install steptrace
Quick Start
Context Manager (Recommended)
from steptrace import Tracer
def main():
a = 1
b = 2
print(a + b)
with Tracer():
main()
Decorator Usage
from steptrace import Tracer
@Tracer().tracer
def main():
a = 1
b = 2
print(a + b)
main()
Log Output
Logs are written to:
.tracer/tracer.log
or, if a log already exists:
.tracer/tracer_1.log
.tracer/tracer_2.log
...
Example Log Entry
--------------------- Step 3 ---------------------
Runtime: 0.0841 ms
/path/to/file.py::main -- line 8
------> Global variables <------
x: int :: 5
------> Local variables <------
y: int :: 10
How It Works
The tracer uses Python’s sys.settrace to intercept execution on every line and logs:
- File name
- Function name
- Line number
- Execution time since last step
- Call stack
- Local and global variables
Only files inside your project workspace are traced to keep output relevant.
Context Manager Behavior
Using the tracer as a context manager ensures:
- Previous trace functions are restored
- Exceptions are not suppressed
with Tracer():
risky_code()
When to Use
- Debugging complex logic
- Understanding unfamiliar codebases
- Teaching / learning Python execution flow
- Inspecting variable evolution over time
Limitations
- Tracing every line may generate large log files
- Not intended for production use
- Performance overhead for long-running programs
License
MIT License — free to use, modify, and distribute.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_steptrace-0.1.0.tar.gz.
File metadata
- Download URL: python_steptrace-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
693b807530ad78874b4f41fdce7a08fbc593e9890dee713857b91bba2d4c776e
|
|
| MD5 |
9a7d762eece8015069fa54e35968fae3
|
|
| BLAKE2b-256 |
b5f574077fbd908378eaa70a1b59177263092b2e187929a45947cdf3672ab7a9
|
File details
Details for the file python_steptrace-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_steptrace-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ff11a5023c0f87b871d7c1238ece3a2f0361391c5701d815877e8520c76734
|
|
| MD5 |
c1ce228cd213ccc4d681f445e066f951
|
|
| BLAKE2b-256 |
d7f8d0d4909542f4f94837de50c8d91294adbd686e7362097195dee9d43f8fde
|