Skip to main content

A colorful, context-rich traceback formatter for Python

Project description

Better-trace

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

Install using
python3 -m pip install better-trace

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 Description
show_locals Shows locals at crash site (default=True)
log_exceptions Logs exceptions to crash.log (default=False)
debugger Enables pdb after exception (default=False)
mode Output style (verbose, context, compact, minimal) (default="verbose")
theme The syntax highlighting theme (default="monokai")
background_color The background color (default="default")

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_var)
NameError: name 'my_va' is not defined

After

Better-trace output

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

License

MIT

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.1.0.tar.gz (8.8 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.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: better_trace-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 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.1.0.tar.gz
Algorithm Hash digest
SHA256 73b1495c78c196e25fd3680006fa8a41529bcedfa0b89e731a1194303170b0c3
MD5 51b66c3f96731342fbbb871b5904b310
BLAKE2b-256 d1476ee4ead840a48b277866e8714e14a4ea9ca08b0caa9ad75cbfb2d7dade36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: better_trace-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0185951d63cd7eb906cab1adbc478278b0a6da20b2f408f30b5b02623d0d8bb
MD5 47f46b8199d057a00c9a68f93ece25d4
BLAKE2b-256 536b254f80d749a036a3e4fb81b57723916233c4e4169cb9d5900cd61ca6e6c4

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