Skip to main content

Human-readable HTML tracebacks for Python exceptions

Project description

Tracebacks for Humans (and Machines)

Fixing bugs is easier with well formatted error messages. Console, HTML and JSON.

PyPI version Tests Coverage

TraceRite in Notebook/HTML and terminal TraceRite formats Python errors in Jupyter notebooks, in plain HTML, and in the terminal: rich variable inspection (left), plus syntax-error highlighting and compact terminal tracebacks (right).

Installation

Python scripts or REPL

pip install tracerite
import tracerite; tracerite.load()

Any error message after that call will be prettified. Handles any syntax errors and uncaught exceptions, even captures logging.exception (optionally).

IPython or Jupyter Notebook

%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.

FastAPI

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.

Sanic

Comes with TraceRite built in. HTML reports are available in debug mode, and console messages are always formatted by Tracerite.

Clarity in complex situations

Exception chain comparison TraceRite renders complex exception chains in chronological order (left). The Python 3.15 built in traceback needs illustrative arrows to follow execution (right).

Features

  • 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.

ExceptionGroup in HTML and terminal Python 3.11+ concurrent execution errors with except* handling are shown clearly in both HTML and terminal output.

Usage

html_traceback(exc)

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.

html_page(exc)

Renders a complete HTML5 document with a TraceRite traceback, ready to serve from a web framework error handler. See tracerite.fastapi.patch_fastapi() for FastAPI integration.

extract_chain(exc)

Extracts exception information as a JSON compatible list of dictionaries—useful for logging, custom formatting, or machine processing.

prettyvalue(value)

Formats any value with smart truncation, array shape display, and SI-scaled numerics. Useful beyond exceptions for debugging tools or custom logging.

extract_variables(locals, source)

Extracts and formats variables mentioned in a line of source code.

load() / unload()

Load or remove TraceRite as the default exception handler for terminal applications. Handles both sys.excepthook and threading.excepthook.

tty_traceback(exc)

Renders an exception as colorful terminal output with ANSI escape codes. Pass an exception object, or call with no arguments inside an except block. file=io.StringIO() may be used for plain text output. The output is well readable by all major LLMs, not only by humans.

See the API documentation for details, or Development guide for contributors.

License

Public Domain or equivalent.

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

tracerite-2.5.2.tar.gz (102.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tracerite-2.5.2-py3-none-any.whl (107.2 kB view details)

Uploaded Python 3

File details

Details for the file tracerite-2.5.2.tar.gz.

File metadata

  • Download URL: tracerite-2.5.2.tar.gz
  • Upload date:
  • Size: 102.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tracerite-2.5.2.tar.gz
Algorithm Hash digest
SHA256 79641bd08214b99ea991699f58d311a731b330b41ff52f4bb7c2c8b57c28f120
MD5 5312df06c7a97e3b461846ae3a02a7b2
BLAKE2b-256 23a8a89871ab6e776ee1fb4db532a764b3dc60fe08cb593427e8e7de96a2f3a8

See more details on using hashes here.

File details

Details for the file tracerite-2.5.2-py3-none-any.whl.

File metadata

  • Download URL: tracerite-2.5.2-py3-none-any.whl
  • Upload date:
  • Size: 107.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tracerite-2.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 910d52ee5cf5633952a2477e1312e9c7427abda2878fd91bb818ab0541d50c5a
MD5 dba95c21f692ea91aebea9c3ef98e503
BLAKE2b-256 a59578468ea37aa76964920217f79512d6a792072d89a9765b6fe61eb441d7d0

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