Skip to content

Commit

Permalink
add ipython extension for rich
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Page committed Jun 6, 2021
1 parent ce4f18c commit 8121532
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
13 changes: 11 additions & 2 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand All @@ -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 <https://ipython.readthedocs.io/en/stable/config/intro.html>`_.

Rich Inspect
------------
Expand Down
4 changes: 3 additions & 1 deletion rich/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
9 changes: 9 additions & 0 deletions rich/_extension.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8121532

Please sign in to comment.