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.0.tar.gz (53.5 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.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: atrace-1.0.0.tar.gz
  • Upload date:
  • Size: 53.5 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.0.tar.gz
Algorithm Hash digest
SHA256 c305750025f4224d198a97bfed8bbd4d3ce5a0e773de3e0bde9c89b9d9f4d5b6
MD5 db2df0248c20f3ab6365f664cebdd093
BLAKE2b-256 e71abd0107ccbf5ffd2aaf65dc409042117221c45181f2e1bb0497a4cf010d45

See more details on using hashes here.

File details

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

File metadata

  • Download URL: atrace-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 936d91cbc1b71b07d571c8f765c72b5a768673bb945ea0fb77d0d138fcb48692
MD5 3775d99b009ec37db870b110b432cc99
BLAKE2b-256 495a0bc288feae6f009115d464308db9b9516a543a5eea93aa60879a71f9e1e2

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