Skip to main content

A colorful, context-rich traceback formatter for Python

Project description

Better-trace

License: MIT PyPI Version Python Version Docs

A Python tool to make tracebacks colorful, context-rich, developer friendly, and turns
python crashes to something you can easily 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 after exception
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

  • 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.2.0.tar.gz (11.3 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.2.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for better_trace-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d6bf7aa231260721c20a7e211755084779708cddda2cc5e1708244b604d07167
MD5 14be2c01caec17c23913d39c01139c8a
BLAKE2b-256 0f32f86ef50402d83cfb2b042495974592ca1a3782280de82a93a8ed01f77700

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for better_trace-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d391fdc724de993023039eb1e6a7755ed74e687cd2f74f6f66a8c3a5671509f3
MD5 a391781f3ee6fe8f907850342e454b7e
BLAKE2b-256 896dc4efbe063f3457da7e38f683cf9c5a2588fda154f18f92dad7bb5766c540

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