Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Colorizing REPL Output With Rich

00:00 Colorizing REPL Output With Rich. The Rich library allows you to use rich text and pretty formatting in the terminal. Rich 5.1.0 included highlighted pretty printing.

00:14 You can use this feature to colorize the standard REPL’s output. However, as a third-party library, first you need to install it. Whenever you’re installing a third-party library in Python, it’s good practice to install it into a virtual environment.

00:32 So, on-screen, you’ll see one being created and activated for macOS or Linux.

00:47 And here are the commands you’d need for Windows.

01:02 Check out this Real Python course if you’d like to know more about virtual environments. With a virtual environment created and activated, here’s the command needed to install Rich.

01:21 Once Rich has been installed, you are ready to colorize your REPL’s output. Here’s how you would do it in an interactive session.

01:44 From this point on, every time you get an output in the REPL session, that output is colorized and formatted. Note that this added capability is temporary.

02:02 It only applies to the current interactive session. Fortunately, though, you know how to use your startup file to add it to every session.

02:29 With this update to the REPL’s startup file, you replicate the output colorizing and formatting behavior in all interactive sessions that have access to the Rich library.

02:39 The tryexceptelse blocks guarantee that the startup file won’t throw an error if Rich isn’t available in the current Python environment that you are using.

02:48 So bear in mind that you’ll need to install Rich into any virtual environment that you are using for the colorizing to work in the REPL. In the next section of the course, you’ll take a look at some of the features that aren’t present in the standard REPL and some alternative REPLs you might want to check out.

Become a Member to join the conversation.