Skip to main content

A colorful, context-rich traceback formatter for Python

Project description

Better-trace

License: MIT PyPI Version Python Version

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

Cloning github repo

You can install better-trace by cloning the git directory by
git clone https://github.com/8er8/better-trace.git
Now you can choose one of the following options to install better-trace

Option 1: Install normally (recommended)

cd better-trace
python3 -m pip install .

Option 2: Install in editable mode (best for development)

cd better-trace
python3 -m pip install -e .

Install using PyPI

Type this command to your shell--
python3 -m pip install better-trace

Notes

  • Requires Python >= 3.11
  • python3 may not work on windows, so use python or py

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

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

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.1.2.tar.gz (9.9 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.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: better_trace-0.1.2.tar.gz
  • Upload date:
  • Size: 9.9 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.2.tar.gz
Algorithm Hash digest
SHA256 c95a7813b510b583bcb6552bfa81e009c16be7cc2b629a5deef307b4fe425581
MD5 bc614fa2b99a9a304289becc9ca1d777
BLAKE2b-256 9ed1110ec93dde207fd6c99eb59960bbaa4150ae0b32ad9ae2220b9df4377340

See more details on using hashes here.

File details

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

File metadata

  • Download URL: better_trace-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c3241adb3c100fc92cb75dc0eaf8150dea0bfaa64bf0c556d0779b6622adf8a
MD5 e35e3f0cd82505ec2ea0d8df607ae17e
BLAKE2b-256 dd436298b1309328531581d5a2340229aa47fc42ac86b0544d24993cadbbb3ce

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