Tracerite: Human-Readable Exception Tracebacks
Tracerite is a Python library that transforms standard Python exception tracebacks into highly readable HTML or formatted TTY output. It is actively maintained, with frequent releases (current version 2.3.1), providing features like chronological ordering of chained exceptions, minimalistic output by pruning irrelevant details, and variable inspection across various environments, including terminals, Jupyter notebooks, and web frameworks like FastAPI and Sanic.
Warnings
- breaking Version 2.0.0 was a complete rewrite, fundamentally changing internal data structures and relying heavily on Python 3.11+'s enhanced exception handling features. Code that interacted with Tracerite's internal APIs from 1.x will break.
- gotcha Tracerite.load() overwrites `sys.excepthook`. If you have a custom exception hook, `tracerite.load()` will replace it. You may need to manually chain your custom hook with Tracerite's or conditionally load Tracerite.
- gotcha While Tracerite's `requires_python` is `>=3.9`, many of the advanced features introduced in v2.0.0, particularly exact cursor positions and optimized exception chain analysis, are based on Python 3.11+'s improved exception handling.
- deprecated Version 1.x series has reached its end of life with v1.2.0. Future development and bug fixes are exclusively in the 2.x series.
- gotcha Tracerite v2.3.0 introduced a significant change in how chained exceptions are presented, adopting a single chronological timeline rather than Python's default convoluted order.
Install
-
pip install tracerite
Imports
- load
import tracerite; tracerite.load()
- patch_fastapi
from tracerite import patch_fastapi; patch_fastapi()
Quickstart
import tracerite
tracerite.load()
def divide_by_zero(a, b):
result = a / b
return result
def main():
x = 10
y = 0
print(f"Attempting to divide {x} by {y}")
divide_by_zero(x, y)
if __name__ == '__main__':
try:
main()
except Exception:
# Tracerite will automatically handle uncaught exceptions
# You won't typically wrap main() in a try-except if using tracerite.load()
# This is just to show the immediate effect if not letting it propagate.
pass
# When run, this will output a formatted traceback to stderr (TTY) or HTML (Jupyter/Web)