Skip to main content

A gradient generator for the Rich library.

Project description

rich-gradient

Python versions PyPI version PyPI downloads uv badge

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 pydantic-extra-types' Color class As of v0.3.0, rich-gradient removed the color logic from rich-gradient and created rich-color-ext

  • 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. red)

Read the docs at rich-gradient.readthedocs.io

Installation

uv (Recommended)

uv add rich-gradient

Pip

pip install rich-gradient

CLI Usage

The package ships with a Typer-based CLI. The first command is text, which prints gradient-styled text. More commands may be added over time.

Quick examples

  • Print gradient text with two color stops:

    rich-gradient text "Hello [b]world[/b]!" -c magenta -c cyan

  • Rainbow gradient (auto-generated colors):

    rich-gradient text "Rainbow!" --rainbow

  • Read from stdin:

    echo "From stdin" | rich-gradient text

  • Wrap in a panel with a title:

    rich-gradient text "Panel content" --panel --title "Gradient Panel"

  • Save to SVG (uses the project terminal theme):

    rich-gradient text "Save me" --save-svg out/example.svg

Common options

  • -c/--color: Repeat to add multiple foreground color stops.
  • -b/--bgcolor: Repeat for background color stops.
  • --rainbow, --hues: Auto-generate a palette if colors aren’t provided.
  • --style, --justify, --overflow, --no-wrap/--wrap, --end, --tab-size, --markup/--no-markup.
  • --panel, --title: Wrap output in a panel with optional title.
  • --width: Console width. --record: enable recording.
  • --save-svg PATH: Save the current render as SVG.

Usage

Basic Gradient Text Example

To print a simple gradient just substitute the Gradient class for the Text class in the rich-gradient library.

from rich.console import Console
from rich_gradient import Gradient

console = Console()
console.print(Gradient("Hello, World!"))

Hello, World!


Gradient Text with Specific Colors

If you want a bit more control of the gradient, you can specify the colors you want to use in the gradient by passing them as a list of colors to the colors parameter.

Color Formats

Color can be parsed from a variety of formats including:

3 or 6 digit hex colors, rgb/rgba colors, and CSS3 Named Colors

Example Code

Specific Two-Color Gradient Example

console.print(
    Text(
        "This a gradient with two colors.",
        colors=["red", "orange"]
    ),
    justify="center"
)

Two Color Gradient


Specific Four-Color Gradient Example

console.print(
    Text(
        "This a gradient uses four specific colors.",
        colors=["red", "#ff9900", "#ff0", "Lime"],
        justify="center"
    )
)

Specific Color Gradient Result

multi-color specific colors


Rainbow Gradient Example

If four colors isn't enough, you can use the 'rainbow' parameter to generate a rainbow gradient that spans the entire spectrum of colors randomly.

console.print(
    Text(
        "This is a rainbow gradient.",
        rainbow=True,
        justify="center"
    )
)

Rainbow Gradient

*The rainbow gradient is generated randomly each time the code is run.


Still inherits from rich.text.Text

Since Gradient is a subclass of Text, you can still use all the same methods and properties as you would with Text.

console.print(
    Gradient(
        "This is an underlined rainbow gradient.",
        rainbow=True,
        style="underline"
    ),
    justify="center"
)
console.line()
console.print(
    Gradient(
        "This is a bold italic gradient.",
        style="bold italic"
    ),
    justify="center"
)
console.line()

Still Text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rich_gradient-0.3.7.tar.gz (16.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rich_gradient-0.3.7-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file rich_gradient-0.3.7.tar.gz.

File metadata

  • Download URL: rich_gradient-0.3.7.tar.gz
  • Upload date:
  • Size: 16.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rich_gradient-0.3.7.tar.gz
Algorithm Hash digest
SHA256 5a455ec1164cc341351d85f0414af8f88e8e8179494824efa3321c3e321d771e
MD5 3defed27bd92acc76680c4a49f456314
BLAKE2b-256 3fd3c1eb7bb0e5941b7a73ca9cd66dc2b3c4de23c2a7e558b2aa656112831b3f

See more details on using hashes here.

File details

Details for the file rich_gradient-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: rich_gradient-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rich_gradient-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5c8dbfc39119de38db1781438a541c846add0152834d9500ca02bf7757180013
MD5 602f5d205f15fae028382347c8dfaa1b
BLAKE2b-256 697ef572fb134432f4c2169d08916cd5414da3e20dc4714929212fb012bdeaf5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page