Terminal magic with Rich and Textual
This is one of the fastest growing projects in the Python space these days. And the creator, Will McGugan is here to give is the whole history and even a peak at the future of Rich and a follow on library called Textual.
Episode Deep Dive
Guest Introduction and Background
Will McGugan is an experienced Python developer and open-source author best known for creating the highly popular libraries Rich and Textual. He has a professional history of working with user interfaces, desktop applications, and web technologies in Python and C++. This background ultimately led Will to explore modern terminal capabilities and create these innovative libraries that push Python’s text-based UIs far beyond the familiar, rudimentary output. Will’s focus is on making terminals more dynamic, interactive, and visually appealing—all while keeping them simple to code against.
What to Know If You're New to Python
Here are some quick resources and core tips to get started with Python in a way that will help you appreciate Rich and Textual’s capabilities:
- Understand Python’s Print Function: Knowing how
print()
works is crucial because Rich provides an alternate printing approach. - Basic Data Structures: Be comfortable with Python dictionaries, lists, and objects so you can grasp Rich’s pretty-printing features.
- Terminal Fundamentals: A basic understanding of how a terminal (Command Prompt, PowerShell, or Bash) interacts with Python scripts will help clarify how Rich and Textual augment output.
Key Points and Takeaways
- Rich's Core Purpose
Rich is all about creating visually pleasing and more informative terminal output in Python. It replaces or extends the typical
print
function with color, formatting, tables, and even syntax highlighting—all from just a few lines of code.- Links and Tools:
- Rich (GitHub)
- Colorama (GitHub) (mentioned as a simpler coloring approach)
- Links and Tools:
- Pretty Printing and Syntax Highlighting
Rich’s custom
print
can automatically pretty-print Python objects (e.g., dictionaries) and even apply syntax highlighting to source code. This significantly reduces the friction of debugging and explorative coding in the REPL or scripts.- Links and Tools:
- Python’s built-in
pprint
(for comparison) - Rich Inspect (GitHub docs)
- Python’s built-in
- Links and Tools:
- Rich Tracebacks and Debugging
Rich can replace standard Python tracebacks with a beautiful, colorized version that shows the relevant code snippet and local variables in each stack frame. This often saves time sifting through plain text tracebacks by highlighting the exact origin of exceptions.
- Links and Tools:
- Interactive Progress Bars, Tables, and More
Rich doesn’t just color output—it has progress bars, aligned tables, markdown rendering, and even tree views. These features transform terminal applications from “plain text” to more dynamic and interactive experiences without heavy dependencies.
- Links and Tools:
- Textual: The Next Level of Terminal Interfaces
Textual builds on Rich to enable mouse- and keyboard-driven user interfaces in the terminal. It gives developers a layout system (docks, scrolling, etc.), widget-based elements, event handling (mouse hover, clicks, etc.), and the possibility of smooth animations—turning the terminal into a retro-style but modern-looking environment.
- Links and Tools:
- CSS-like Styling in the Terminal
Textual is heavily influenced by modern web frameworks and even uses a CSS-like approach for styling widgets. While not full CSS, it’s close enough that web developers will feel at home fine-tuning their terminal layout and style.
- Links and Tools:
- Vue.js (Official Site) (mentioned as an inspiration)
- Textual styling discussion (GitHub issues)
- Links and Tools:
- Async and Performance Considerations
Both Rich and Textual tap into modern Python features like
async
/await
, allowing them to efficiently handle updates, animations, or user input without blocking. This approach helps run real-time UI components even inside the console environment.- Links and Tools:
- Windows, macOS, Linux, and Jupyter Compatibility
Rich and Textual aim to work seamlessly on Windows’ new terminal, older command prompts, macOS, Linux terminals, and even Jupyter Notebooks. For the few features that vary by platform (e.g., older Windows color limitations), Rich gracefully degrades to ensure everything is usable for developers.
- Links and Tools:
- Open Source Sustainability
Will McGugan transitioned to full-time open source, relying on GitHub Sponsors and Tidelift so that large companies and individuals can financially support ongoing development. This highlights a broader community shift, where widely used Python projects seek sustainable backing for maintenance.
- Links and Tools:
- filesystem (pyfilesystem) Mention Will also created and maintained PyFilesystem, an abstraction layer for working with local and remote file systems through a single Pythonic interface. This library integrates multiple file systems (S3, FTP, ZIP archives, etc.) in a consistent way.
- Links and Tools:
Interesting Quotes and Stories
- Will, on terminal UI limitations versus Rich’s goals: “I was surprised how well terminals handle 60 frames per second animations these days. They’re basically hardware-accelerated, and no one was taking advantage of that.”
- Regarding open-source support, Will highlights the crucial difference between hobby projects and business-critical libraries: “So many people benefit from open source. If your project depends on Rich, sponsoring it helps ensure it’s still around in a year or five.”
Key Definitions and Terms
- Terminal UI (TUI): A user interface that primarily uses text and characters rather than a graphical environment, often enhanced through ANSI codes and color sequences.
- ANSI Codes: Special formatting syntax embedded in text output that can change colors, styles, or positioning in terminals.
- Syntax Highlighting: The capability to color and style code elements (keywords, strings, variables) for more readable display.
Learning Resources
Below are some curated learning paths to deepen your Python knowledge.
- Python for Absolute Beginners: A comprehensive, hands-on introduction to Python that covers fundamental concepts to help you comfortably explore libraries like Rich and Textual.
- Modern APIs with FastAPI and Python: If you want to pair interactive terminal apps with robust back-end services, this FastAPI course could be a next step.
- Getting started with pytest: Testing your terminal-based applications with pytest ensures reliability for the advanced features Rich and Textual bring.
Overall Takeaway
Rich and Textual demonstrate the modern evolution of Python’s terminal capabilities. These libraries offer a near-graphical UI experience directly in the console, blending color, widgets, mouse events, and even CSS-like styling. From debugging via brilliant tracebacks to building full-blown, responsive text-based interfaces, Rich and Textual combine ease of use with cutting-edge design for Pythonistas looking to do more in their terminal.
Links from the show
Rich: github.com
Textual: github.com
Pyfilesystem: pyfilesystem.org
A Look At – and Inside – Textual Video: youtube.com
ObjExplore: reposhub.com
ghtop: ghtop.fast.ai
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy