Skip to content

rich-gradient

uv badge with text endpoint url equals https colon slash slash raw dot githubusercontent dot com slash astral dash sh slash uv slash main slash assets slash badge slash v0 dot json on a white background Python compatibility badge showing versions 3.10 3.11 3.12 3.13 on a blue background with the Python logo PyPI badge displaying rich underscore gradient on a blue background Version badge showing 0.3.2 on a gray background rich

gradient example

This library is a wrapper of the great rich library that extends rich.text.Text to allow for the easy generation gradient text from either user entered colors or randomly if no colors are entered.

Borrowing from rich-color-ext rich_gradient extends the rich standard colors to include:

  • 3 or 6 digit hex code (e.g. #f00 or #ff0000)
  • RGB color codes (e.g. rgb(255, 0, 0))
  • RGB tuples (e.g. (255, 0, 0))
  • CSS3 Color Names (e.g. rebeccapurple)

Installation

uv add rich-gradient

Pip

pip install rich-gradient

Usage

Text Example

To print a simple gradient import the Text class from in the rich_gradient library:

Hello, World!

Gradient

If just text is boring, rich_gradient.gradient.Gradient allows you to apply a gradient to any rich.console.ConsoleRenderable. Such as a rich.panel.Panel or rich.table.Table;

table = Table(
    title="Gradient Table Example",
    border_style="bold",
)
table.add_column(
    "Renderable",
    style="bold",
    vertical="middle",
    justify="right"
)
table.add_column("Works w/Gradient", justify="left", style="bold")
renderables = [
    "Text",
    "Panel",
    "Syntax",
    "Table",
    "Live",
    "Group",
    "Markdown"
]
for renderable in renderables:
    table.add_row(
        renderable,
        "[b]:heavy_check_mark:[/b]"
    )

console.print(Gradient(table, rainbow=True), justify="center")

Gradient Table Example