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
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
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
Context
Balanced output with surrounding lines
Compact
Short and readable
Minimal
Just the last frame and the error line
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file better_trace-0.1.1.tar.gz.
File metadata
- Download URL: better_trace-0.1.1.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09d9fa1780a721e4f279dd122e5834ff2b41912e97a776f7bf235cc3e2146bdd
|
|
| MD5 |
bac6c30166f4fbf838aa45601d212b5f
|
|
| BLAKE2b-256 |
1eec2f9eddaf7922d6102965af848307732e4a3670460a98effa3be3f300f5e6
|
File details
Details for the file better_trace-0.1.1-py3-none-any.whl.
File metadata
- Download URL: better_trace-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
936b338d79ed2691fd7f651bf5f1c72e1d0f16e4e35fd83925e2969305e3438a
|
|
| MD5 |
4855bb6b32dddce980da0979c2c1110e
|
|
| BLAKE2b-256 |
b7c3d49aebcff556c621f9d8983bf06438954909bb756ffc1bcf89077059562f
|