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).

To display the trace:

python3 -m atrace 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:

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 

Compatibility

Requires python version 3.10 or higher.

Tested with:

  • cpython
  • pypy
  • Thonny

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.0.1.tar.gz (54.2 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.0.1-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: atrace-1.0.1.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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.0.1.tar.gz
Algorithm Hash digest
SHA256 695a393753fdec0a3bfdd6ad6232eac01cc9621ada2d33d5b7fa94e3bf11810d
MD5 a495b3b039fe98e28fd0cb7f36703d32
BLAKE2b-256 a45d907b99627f91f36a23177f91748fb303a1ef30717072192c4e932105e939

See more details on using hashes here.

File details

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

File metadata

  • Download URL: atrace-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 147b55ead22c1e46233f16e23c09c5ce19fb98dd0d04dd650c04d402003683d2
MD5 e155986acde6e4451b41820612c49d52
BLAKE2b-256 f4db1a038a645070c1c3835e491c21c0a84f98f97ee19d2df5c94e50bd330fbb

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