Better-trace
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;
python3may not work on windows, so usepythonorpy
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
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_va)
NameError: name 'my_va' is not defined
After
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
Metadata
Release files for better-trace 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| better_trace-0.3.0.tar.gz | 14.2 kB | Without provenance | Details for better_trace-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| better_trace-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for better_trace-0.3.0-py3-none-any.whl |
Total release size: 27.2 kB
Release files / better_trace-0.3.0.tar.gz
| Download URL | better_trace-0.3.0.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
780be0f34359533703605d0817a9263ef6d93ea4241bec6cc8470f83ec50a026
|
|
BLAKE2b-256 checksum How to use checksums |
6b7ef7f4138ac7ec2a338dffaf7c6e1d74a858dd5a3af3a7a4df80c1e24709ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / better_trace-0.3.0-py3-none-any.whl
| Download URL | better_trace-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc36a7630132185ea5a21a2b8e6159d5fe0463d123777e8ccfdea47fb78d7c17
|
|
BLAKE2b-256 checksum How to use checksums |
8d53a7643cc1917ac64b31cf385f8c52e2e4f910dce6852fc4acecfc7572859b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for better-trace 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.