rich.traceback

class rich.traceback.Traceback(trace: rich.traceback.Trace = None, width: Optional[int] = 88, extra_lines: int = 3, theme: Optional[str] = None, word_wrap: bool = False)[source]

A Console renderable that renders a traceback.

Parameters
  • trace (Trace, optional) – A Trace object produced from extract. Defaults to None, which uses the last exception.

  • width (Optional[int], optional) – Number of characters used to traceback. Defaults to 100.

  • extra_lines (int, optional) – Additional lines of code to render. Defaults to 3.

  • theme (str, optional) – Override pygments theme used in traceback.

  • word_wrap (bool, optional) – Enable word wrapping of long lines. Defaults to False.

classmethod extract(exc_type: Type[BaseException], exc_value: BaseException, traceback: Optional[traceback]) → rich.traceback.Trace[source]

Extrace traceback information.

Parameters
  • exc_type (Type[BaseException]) – Exception type.

  • exc_value (BaseException) – Exception value.

  • traceback (TracebackType) – Python Traceback object.

Returns

A Trace instance which you can use to construct a Traceback.

Return type

Trace

classmethod from_exception(exc_type: Type, exc_value: BaseException, traceback: Optional[traceback], width: Optional[int] = 100, extra_lines: int = 3, theme: Optional[str] = None, word_wrap: bool = False)rich.traceback.Traceback[source]

Create a traceback from exception info

Parameters
  • exc_type (Type[BaseException]) – Exception type.

  • exc_value (BaseException) – Exception value.

  • traceback (TracebackType) – Python Traceback object.

  • width (Optional[int], optional) – Number of characters used to traceback. Defaults to 100.

  • extra_lines (int, optional) – Additional lines of code to render. Defaults to 3.

  • theme (str, optional) – Override pygments theme used in traceback.

  • word_wrap (bool, optional) – Enable word wrapping of long lines. Defaults to False.

Returns

A Traceback instance that may be printed.

Return type

Traceback

rich.traceback.install(*, console: rich.console.Console = None, width: Optional[int] = 100, extra_lines: int = 3, theme: Optional[str] = None, word_wrap: bool = False) → Callable[source]

Install a rich traceback handler.

Once installed, any tracebacks will be printed with syntax highlighting and rich formatting.

Parameters
  • console (Optional[Console], optional) – Console to write exception to. Default uses internal Console instance.

  • width (Optional[int], optional) – Width (in characters) of traceback. Defaults to 100.

  • extra_lines (int, optional) – Extra lines of code. Defaults to 3.

  • theme (Optional[str], optional) – Pygments theme to use in traceback. Defaults to None which will pick a theme appropriate for the platform.

  • word_wrap (bool, optional) – Enable word wrapping of long lines. Defaults to False.

Returns

The previous exception handler that was replaced.

Return type

Callable