diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst index 62a34bf4..464ebdd6 100644 --- a/docs/source/introduction.rst +++ b/docs/source/introduction.rst @@ -69,8 +69,8 @@ If you would rather not shadow Python's builtin print, you can import ``rich.pri Continue reading to learn about the more advanced features of Rich. -Python in the REPL ------------------- +Rich in the REPL +---------------- Rich may be installed in the REPL so that Python data structures are automatically pretty printed with syntax highlighting. Here's how:: @@ -85,6 +85,15 @@ You can also use this feature to try out Rich *renderables*. Here's an example:: Read on to learn more about Rich renderables. +IPython Extension +~~~~~~~~~~~~~~~~~ + +Rich also includes an IPython extension that will do this same pretty install + pretty tracebacks. Here's how to load it:: + + In [1]: %load_ext rich + +You can also have it load by default by adding `"rich"` to the ``c.InteractiveShellApp.extension`` variable in +`IPython Configuration `_. Rich Inspect ------------ diff --git a/rich/__init__.py b/rich/__init__.py index c75333f7..d5ce4b5d 100644 --- a/rich/__init__.py +++ b/rich/__init__.py @@ -1,7 +1,9 @@ """Rich text and beautiful formatting in the terminal.""" import os -from typing import Any, IO, Optional, TYPE_CHECKING +from typing import IO, TYPE_CHECKING, Any, Optional + +from ._extension import load_ipython_extension __all__ = ["get_console", "reconfigure", "print", "inspect"] diff --git a/rich/_extension.py b/rich/_extension.py new file mode 100644 index 00000000..c0e13bec --- /dev/null +++ b/rich/_extension.py @@ -0,0 +1,9 @@ +from typing import Any + + +def load_ipython_extension(ip: Any) -> None: + from rich.pretty import install + from rich.traceback import install as tr_install + + install() + tr_install()