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

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_steptrace-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 97ba6c0d1f13cbac6280a5f86849657a9550f0eb6e1f1fe049eb1657598c91fc
MD5 b45d7f664de3546c713f16027dc2286e
BLAKE2b-256 284f0fe46cc29847b517bb3506940f3bf20125c903d4b13d94bf0fb7a595587a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_steptrace-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7fb8201b93ad5772fdd0d372615108e7dbbc04075e1f4fb9c3cf911f6ee8c049
MD5 ffaeda936ffcb0beb552a9f942410736
BLAKE2b-256 962256298b353be285f8fe4568de45e5b383bb71c585d2355b5230c2f17c53e5

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