Skip to main content

A colorful, context-rich traceback formatter for Python

Project description

Better-trace

License: MIT PyPI Version Python Version Docs Code style: black

A Python tool to make tracebacks colorful, context-rich, developer-friendly, and visually easier to read

Features

  • A colorful traceback powered by rich
  • Multiple modes
    • Verbose - Gives you all the information
    • Context - A balanced view of the traceback (Recommended)
    • Compact - Shows only the last 3 frames, good for quick debugging
    • Minimal - Shows only the last frame, containing the essentials to quickly debug, not for advanced debugging
  • Smart suggestions for NameError
  • Context view (shows the surrounding lines; only for verbose and context mode)
  • ExceptionGroup support
  • Thread + Unraisable hooks
  • Optional logging to file
  • Built-in post mortem debugger (pdb)

Installation

Type this command to your shell:

python3 -m pip install better-trace

Note: Requires python >= 3.11; python3 may not work on windows, so use python or py

Installation for contributors

Clone the better-trace github repo and install better-trace (in editable mode)

git clone https://github.com/8er8/better-trace.git
cd better-trace
python3 -m pip install -e .

Quick example

from better_trace import initialize

initialize()

# a crash
1 / 0

Configuration

initialize(
    show_locals=True,
    log_exceptions=False,
    debugger=False,
    mode="verbose",
    theme="monokai",
    background_color="default",
)
Option Type Default Description
show_locals bool True Shows locals at crash site
log_exceptions bool False Logs exceptions to crash.log
debugger bool False Enables pdb post mortem debugging
mode str "verbose" Output style (verbose, context, compact, minimal)
theme str "monokai" The syntax highlighting theme
background_color str "default" The background color

Mode preview

Verbose

full traceback + locals + context
Shows everything
Verbose mode output

Context

Balanced output with surrounding lines
Context mode output

Compact

Short and readable
Compact mode output

Minimal

Just the last frame and the error line
Minimal mode output

Better-trace demo

from better_trace import demo

demo()

Reverting back

from better_trace import revert

revert()

Before and After

Before

Traceback (most recent call last):
  File "C:\python\Adamya\a.py", line 10, in <module>
    main()
  File "C:\python\Adamya\a.py", line 7, in main
    print(my_va)
NameError: name 'my_va' is not defined

After

Better-trace output

Why better-trace?

Because the default python traceback is informative but is really ugly and sometimes hard to read.

But better-trace makes tracebacks easier to read by--

  • Making tracebacks easier to read
  • Giving more info
  • Coloring and syntax higlighting powered by rich
  • Four different modes
  • And much more

Notes

  • Optionally requires rich
  • Works best in modern terminals
  • Designed for developer experience (not beginner-oriented)

Credits

Main developer

Adamya Mondal - creator, designer, and maintainer of this project

Built with

  • Python Standard Library
  • rich (Huge credits to developers of rich)

Inspiration

Python's default traceback is really minimal
So we fixed it to make it more developer-friendly

Contributions

  • Adamya Mondal (for being the main dev)
  • Open for contributors

Note: Contributors who are willing to contribute better-trace should read the 'Installation for contributors' section

License

This project is licensed under the MIT license

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

better_trace-0.3.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

better_trace-0.3.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file better_trace-0.3.0.tar.gz.

File metadata

  • Download URL: better_trace-0.3.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for better_trace-0.3.0.tar.gz
Algorithm Hash digest
SHA256 780be0f34359533703605d0817a9263ef6d93ea4241bec6cc8470f83ec50a026
MD5 fb6456a78bb38f4d39da10d5a04411d5
BLAKE2b-256 6b7ef7f4138ac7ec2a338dffaf7c6e1d74a858dd5a3af3a7a4df80c1e24709ab

See more details on using hashes here.

File details

Details for the file better_trace-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: better_trace-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for better_trace-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc36a7630132185ea5a21a2b8e6159d5fe0463d123777e8ccfdea47fb78d7c17
MD5 b056f07c32c9c72f30c05086fb2af16c
BLAKE2b-256 8d53a7643cc1917ac64b31cf385f8c52e2e4f910dce6852fc4acecfc7572859b

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