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

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_steptrace-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 1f08ebd0775d9f146a7b6e27c6f95c4b6140b846e0de6a9f31fa52bb675e0614
MD5 6d24fe29ea27c06564364af417501118
BLAKE2b-256 8ca1a0f82de3b8c9526cd1e3bbcc96772158e060549697ef5243b44a4a09e57a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_steptrace-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3b3a987e42df447144a3c4a55bf27a0e13245b06cbef4dc9ea3cb0562ca9e74
MD5 9a5f3c279a1786cde94a4b341ed93168
BLAKE2b-256 494112941c1a49c7efbcdf9810983629cef1df634b65c2141f6140331f1d2927

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