Skip to main content

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 python-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

python_steptrace-0.2.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_steptrace-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file python_steptrace-0.2.0.tar.gz.

File metadata

  • Download URL: python_steptrace-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for python_steptrace-0.2.0.tar.gz
Algorithm Hash digest
SHA256 901ec303a88160beeba14c616a372964f4e95ce75574207d1b78a07fb0119e12
MD5 c19dfee901d267b4c4d50d468b29740e
BLAKE2b-256 168de6957f89d1504482faf7b123c1d1851727b1f59424412c8630701430067f

See more details on using hashes here.

File details

Details for the file python_steptrace-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_steptrace-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 452d3d2569965a7d2a1288c90f7cac7010a401afff6d098f1f787ea3c2569e38
MD5 a1256912728795406363f58e9d2a1a87
BLAKE2b-256 64f1c378d300fd4f9bf56e3670599191995d6161cb877022aed99cc36a8f9f17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page