Beautiful, readable error messages for Python, with text and HTML formatting.
pip install traceriteimport tracerite; tracerite.load()Any error message after that call will be prettified. Handles any syntax errors and uncaught exceptions, even captures logging.exception (optionally).
%pip install tracerite
%load_ext tracerite
This enables tracebacks in text or HTML format depending on where you are running. Add to ~/.ipython/profile_default/startup/tracerite.ipy to make it load automatically for all your ipython and notebook sessions. Alternatively, put the two lines at the top of your notebook.
Add the extension loader at the top of your app module:
from tracerite import patch_fastapi; patch_fastapi()This monkeypatches Starlette error handling and FastAPI routing to work with HTML tracebacks. Note: this runs regardless of whether you are in production mode or debug mode, so you might want to call that function only conditionally in the latter.
Comes with TraceRite built in whenever running in debug mode.
TraceRite shows even complex exception chains in chronological order, as opposed to the convoluted order of Python's own tracebacks where the entry point func() is near bottom and the flow jumps back and forth.
- Chronological order - Single timeline with the program entry point is at top, and the finally uncaught exception bottom.
- Minimalistic output - Smart pruning to show only relevant pieces of information, excluding library internals where not relevant and avoiding any repetition.
- ExceptionGroups - Full tracebacks of the subexceptions from exceptions that occurred in parallel execution.
- Variable inspection - See the values of your variables in a pretty printed HTML format, Terminal or JSON-compatible machine-readable dict.
- JSON output - Intermediady dict format is JSON-compatible, useful for machine processing and used by our HTML and TTY modules.
- HTML output - Works in Jupyter, Colab, and web frameworks such as FastAPI and Sanic as the debug mode error handler.
- TTY output - Colorful, formatted tracebacks for terminal applications and Python REPL.
- Custom Styling - Theme with your colors by defining CSS variables or tty.COLORS.
- Automatic dark mode - Saves your eyes.
Python 3.11+ introduced ExceptionGroup for parallel execution errors (e.g., asyncio.TaskGroup). TraceRite displays these clearly.
Renders an exception as interactive HTML that can be included on a page. Pass an exception object, or call with no arguments inside an except block to use the current exception.
Extracts exception information as a list of dictionaries—useful for logging, custom formatting, or machine processing.
Formats any value with smart truncation, array shape display, and SI-scaled numerics. Useful beyond exceptions for debugging tools or custom logging.
Extracts and formats variables mentioned in a line of source code.
Load or remove TraceRite as the default exception handler for terminal applications. Handles both sys.excepthook and threading.excepthook.
Renders an exception as colorful terminal output with ANSI escape codes. Pass an exception object, or call with no arguments inside an except block.
See the API documentation for details, or Development guide for contributors.
Public Domain or equivalent.
