Skip to main content

Generate trace tables for simple programs

Project description

Atrace

build status PyPI - Version Ask DeepWiki

Automatically prints a trace table of simple programs

This module is intended for beginner programmers.

The trace table of examples/small.py is:

╭──────┬───┬───┬──────────────┬──────────────┬─────────────────┬─────────╮
│ line │ x │ y │ greet        │ (greet) name │ (greet) message │  output │
├──────┼───┼───┼──────────────┼──────────────┼─────────────────┼─────────┤
│    3 │ 1 │ 3 │              │              │                 │         │
│    6 │ 2 │   │              │              │                 │         │
│    6 │ 3 │   │              │              │                 │         │
│    8 │   │   │              │              │                 │    x: 3 │
│   11 │   │   │ greet("Bob") │        "Bob" │                 │         │
│   12 │   │   │ │            │              │       "Hi Bob!" │         │
│   13 │   │   │ └─ "Hi Bob!" │              │                 │         │
│   16 │   │   │              │              │                 │ Hi Bob! │
╰──────┴───┴───┴──────────────┴──────────────┴─────────────────┴─────────╯

Installing the package

The package is available on pypi.

Install the latest version with uv, pip, the Thonny package manager, etc.

Generating a trace for code under development

Just import the module at the top of your file, like in examples/small.py

import atrace 

x, y = 1, 3
...

Every time you run the program the trace table will be printed when the program exits.

The trace is printed even if the program is interrupted or an uncaught exception is raised.

Programs that use input to interact with the user work, the trace is only printed at the end of the execution.

Running as a tool

You can display the trace and other visualizations for existing programs (no need to import atrace in the program).

Note: If you are using uv replace the python3 at the beginning with uv run

To display the trace:

python3 -m atrace examples/fizzbuzz.py

To save the trace to an svg file:

python3 -m atrace examples/fizzbuzz.py --svg local/fizzbuzz.svg

To display the trace as markdown:

python3 -m atrace.markdown examples/fizzbuzz.py 

To display a line-by-line animation of the trace:

python3 -m atrace.animated examples/fibonacci.py

To display a histogram of how many times each line in a program is executed: (svg output works the same as for the trace)

python3 -m atrace.histogram examples/nested_loops.py

To display a line-by-line animation of the histogram:

python3 -m atrace.animated_histogram examples/fizzbuzz.py 

To display the program with line numbers and syntax highlighting: (svg output also works here)

python3 -m atrace.code examples/fizzbuzz.py 

Compatibility

Requires python version 3.10 or higher.

Tested with:

  • cpython
  • pypy
  • Thonny (with the cpython backend)

Does not work well with

  • Multithreaded programs
  • Multi-module programs
  • Debuggers
  • Classes
  • Context managers

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

atrace-1.1.1.tar.gz (56.8 kB view details)

Uploaded Source

Built Distribution

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

atrace-1.1.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file atrace-1.1.1.tar.gz.

File metadata

  • Download URL: atrace-1.1.1.tar.gz
  • Upload date:
  • Size: 56.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for atrace-1.1.1.tar.gz
Algorithm Hash digest
SHA256 1badf5158fd470413d64dbafdfb84da2c8f9b070d813d81c431ede95543a7fd5
MD5 1ba220d7006911bcf3cd137e35706f2d
BLAKE2b-256 406f3a8f2d235eea22160cabed085ba18ea3684cc6a15d7a64fd5844c2ac2e89

See more details on using hashes here.

File details

Details for the file atrace-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: atrace-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for atrace-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b54cc96a2c4b56a0c333a0d5a7c6bb2b53e135e7481b31bfcbb4c9b7092becb
MD5 86d0877c15ae2ae0e0f41e6eb0f1a10a
BLAKE2b-256 ca2ecff993dca8045e19135408714d56c24b7f00eb38544672fa74b554defc62

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