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.1.3.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.1.3-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_steptrace-0.1.3.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.1.3.tar.gz
Algorithm Hash digest
SHA256 ea8f707832b62e7b7539cb82ab251ce54fbf7b2f0cfb77d6156a882512d574d6
MD5 96f6888ea053209e45122f3f5e8b9bf8
BLAKE2b-256 ec9954e8e5cec724221bb18ed4cf97534cfc1e148302d8334bb3efef83d324ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_steptrace-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d12dd01f0ece021b02e929bacb504fb88dc073d1f1f9f8c678914c4ffd3dfb12
MD5 e54d5094502835beb01f050df679bea1
BLAKE2b-256 88c0be7e50d33d4c9426f994008760d01572fefcb68c2a52a190f375bde4e9b4

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