Skip to main content

A gradient generator for the Rich library.

Project description

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 (Recommended)

uv add rich-gradient

Pip

pip install rich-gradient

Usage

Basic Gradient Example

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

from rich.console import Console
from rich_gradient import Gradient

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

Hello, World!


Gradient 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

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.1.tar.gz (13.1 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.1-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rich_gradient-0.3.1.tar.gz
  • Upload date:
  • Size: 13.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for rich_gradient-0.3.1.tar.gz
Algorithm Hash digest
SHA256 aef2f5bc6aef05e3b83748304db83392f030290ac93674917c65699eeffb95c2
MD5 8d19ee075821662b4fb4e79d3407e2d2
BLAKE2b-256 54e0cb88a2804e96f6aae409c28955a0168c783a3d9ea0992d65b6230e60f877

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rich_gradient-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ebbd7c446fd79cb524fcc1c09f67b399e756f8daed02ab3e807990e9879a771
MD5 0111048cd1502b8468abd50c9fc83543
BLAKE2b-256 07df34e5326bd2045a618870dd782bb5f2dc246f68dc18e403c9896bd50c4e55

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