🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

rich-gradient

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rich-gradient

A gradient generator for the Rich library.

0.3.2
PyPI
Maintainers
1

rich-gradient

Python PyPI PyPI - Downloads uv

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 add rich-gradient

Pip

pip install rich-gradient

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(
    Gradient(
        "This a gradient with two colors.",
        colors=["red", "orange"]
    ),
    justify="center"
)

Two Color Gradient

Specific Four-Color Gradient Example

console.print(
    Gradient(
        "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(
    Gradient(
        "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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts