Rich: Python library for rich text and terminal formatting

repository·main·Indexed 13 days ago

https://github.com/textualize/rich

A Python library for rendering rich text, tables, progress bars, syntax highlighting, and markdown in the terminal. Version 15.0.0 features include the Console object for advanced output control, a pretty-printing REPL integration, a logging handler, and the rich-cli for command-line usage.

Tokens
75.1K
Snippets
320
Records
389
Agent score
98%

What's inside Rich

  1. Projects using Rich

    main

    Rich is used by a wide variety of prominent Python projects to enhance terminal output, including:

    • BrainRender: 3D neuro-anatomical data visualization.
    • Ciphey: Automated decryption tool.
    • Scalene: High-performance CPU and memory profiler.
    • StarCli: GitHub trending project browser.
    • cve-bin-tool: Vulnerability scanner for common libraries.
    • nf-core/tools: Community helper tools.
    • pdbr: Enhanced debugging using pdb + Rich.
    • Felicette: Satellite imagery tool.
    • SeleniumBase: Selenium and pytest automation/testing.
    • ffsubsync: Automatic subtitle synchronization.
    • Norfair: Real-time 2D object tracking.
    • ansible-lint: Ansible playbook practice checker.
    • Molecule: Ansible testing framework.

    You can find many more projects that depend on Rich on the Rich dependents page.

  2. Control wrapping and cropping

    main

    Rich automatically wraps text and crops content to fit the terminal width.

    • Soft Wrapping: To disable automatic word wrapping and let text run onto the next line (like standard print), set soft_wrap=True in console.print().
    • Cropping: By default, console.print() has crop=True, which prevents content from running onto the next line. Setting soft_wrap=True automatically disables cropping.
    # Disable word wrapping
    console.print("This is a very long line that will not wrap.", soft_wrap=True)
  3. Understand standard 8-bit terminal colors

    main
    Rich supports standard 8-bit colors commonly found in terminal software. Note that the first 16 colors in the standard palette are typically defined by your specific terminal emulator or system settings, so their exact appearance may vary from the rendered output in documentation.
  4. Add horizontal lines to Tables

    main

    By default, tables only show a line under the header. To add more lines:

    • Between all rows: Set show_lines=True in the Table constructor.
    • Force a line after a specific row: Set end_section=True when calling add_row(), or call add_section() to insert a line between the current and subsequent rows.
  5. Enable beautiful tracebacks

    main
    Rich can provide much more readable and informative tracebacks than standard Python exceptions. You can configure Rich as the default traceback handler so that all uncaught exceptions are rendered with enhanced formatting and more code context.
  6. Use beautiful tracebacks

    main
    Rich can provide much more readable tracebacks than standard Python exceptions. You can configure Rich to be the default traceback handler so that all uncaptured exceptions are automatically processed and rendered beautifully.
  7. Use multiple Progress instances for different columns

    main
    A single Progress instance does not support different column configurations per task. If you need different sets of columns for different tasks, you must use multiple Progress instances. You can display multiple Progress instances simultaneously within a Live display.