A gradient generator for the Rich library.
Project description
Purpose
rich-gradient layers smooth foreground and background gradients on top of Rich renderables.
It includes a drop-in Text subclass, wrappers for Panel and Rule, utilities for building palettes, and
a rich-click (Click) CLI for trying gradients from the terminal.
Highlights
- Works anywhere Rich expects a
ConsoleRenderable, including panels, tables, and live updates. - Generates color stops automatically or from CSS color names, hex codes, RGB tuples, or
rich.color.Colorobjects. - Supports foreground and background gradients, rainbow palettes, and deterministic color spectrums.
- Ships with ready-to-use renderables:
RuleSpectrum- And their animated counterparts.
- Includes a CLI for quick experiments and SVG export for documentation or asset generation.
- Auto-bootstraps a configuration file (
~/.rich-gradient) where you can toggle animation globally and customise the default spectrum palette.
What's new in v0.3.9
- CLI docs now reflect the Click + rich-click commands (
print,panel,rule,markdown) with up-to-date options and examples. - Help text across CLI options uses the rich markup styling from
text_command.pyfor consistency. - Tests run without an editable install because
tests/conftest.pyprependssrc/tosys.path. - Docs CSS forces the page background to the theme color to eliminate the black/transparent flash at the top of pages.
Installation
rich-gradient targets Python 3.10+.
uv
# Recommended: use uv
uv add rich-gradient
# or via `uv pip`
uv pip install rich-gradient
Pip
Or with pip:
# via pip
pip install rich-gradient
📘 Read the Docs
CLI Usage
The CLI is built with Click + rich-click. Subcommands:
print: gradient text. Options:--colors/-c,--bgcolors,--rainbow,--hues,--style,--justify,--overflow,--no-wrap,--end.rule: gradient rule. Options:--title,--title-style,--colors,--bgcolors,--rainbow,--hues,--thickness,--align,--end.panel: gradient panel. Options:--colors,--bgcolors,--rainbow,--hues,--title,--title-style,--title-align,--subtitle,--subtitle-style,--subtitle-align,--style,--border-style,--padding,--vertical-justify,--text-justify,--justify,--expand/--no-expand,--width,--height,--box,--end,--animate,--duration.markdown: gradient markdown. Options:--colors,--bgcolors,--rainbow,--hues,--style,--justify,--vertical-justify,--overflow,--no-wrap,--end,--animate,--duration.
Quick examples:
- Gradient text:
rich-gradient print "Hello [b]world[/b]!" -c magenta,cyan - Rainbow text:
rich-gradient print "Rainbow!" --rainbow - Panel with title:
rich-gradient panel "Panel content" -c red,blue --title "Gradient Panel" - Rule with title:
rich-gradient rule --title "Section" -c "#f00,#0ff" - Gradient markdown:
rich-gradient markdown "# Title" --colors "#ff0,#0ff" --justify center
Contributor notes
- Tests:
pytestworks without an editable install becausetests/conftest.pyaddssrc/tosys.path. No extra env tweaks needed; just install deps and runpytest.
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!"))
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:
Example Code
Specific Two-Color Gradient Example
console.print(
Text(
"This a gradient with two colors.",
colors=["red", "orange"]
),
justify="center"
)
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
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"
)
)
*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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rich_gradient-0.3.9.tar.gz.
File metadata
- Download URL: rich_gradient-0.3.9.tar.gz
- Upload date:
- Size: 17.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e0cd23021166d9eb299a397b254b34fe45ef8c367fc90291408c9b0f69acd39
|
|
| MD5 |
a7d1990d0a6c3723e77413b3eb64180c
|
|
| BLAKE2b-256 |
b8de3c91a072ed77870117674ec2fa7dd127422362cb1e059b96cf4cac19bf77
|
File details
Details for the file rich_gradient-0.3.9-py3-none-any.whl.
File metadata
- Download URL: rich_gradient-0.3.9-py3-none-any.whl
- Upload date:
- Size: 64.9 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f135e74d6787d326cbcd425ce7f38c7f8bc57739c58a1f641393e17c115d4f6
|
|
| MD5 |
7f688aa72ebf5015a63c0ca51b9444e8
|
|
| BLAKE2b-256 |
e931e5fd8c5fd81483451f01b107747fd7150e4ffd60191d4d7bece44c854c27
|