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,
gradient-aware Markdown, animated variants, and utilities for building
palettes.
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 seedable color spectrums.
- Ships with ready-to-use renderables:
AnimatedText,AnimatedGradient,AnimatedPanel,AnimatedRule, andAnimatedMarkdownfor live gradient updates.- Loads optional JSON configuration from
~/.rich-gradient/config.json, where you can toggle animation globally and customize the default spectrum palette.
What's new in v0.3.12
-
Changed gradient segment rendering is shared across
Gradient,Rule, andAnimatedRulefor more consistent cell-aware output. -
Changed CLI functionality moved to
rich-gradient-cli; this package is the core renderable library. -
Added RGB tuple color stops and stricter tuple channel validation.
-
Fixed
RuleandAnimatedRuleempty-renderable fallbacks and thickness handling. -
Fixed
AnimatedGradientrefresh-rate validation and restart-after-stop behavior. -
See the CHANGELOG for more details.
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
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
Use Text when you want a drop-in rich.text.Text replacement with gradient
spans applied to the text itself.
from rich.console import Console
from rich_gradient import Text
console = Console()
console.print(Text("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 aren't enough, you can use the 'rainbow' parameter to generate a rainbow gradient that spans the full spectrum palette.
console.print(
Text(
"This is a rainbow gradient.",
rainbow=True,
justify="center",
),
)
Use Spectrum(hues=..., seed=...) when you need reproducible color stops.
Still inherits from rich.text.Text
Since Text is a subclass of rich.text.Text, you can still use all
the same methods and properties as you would with Text.
console.print(
Text(
"This is an underlined rainbow gradient.",
rainbow=True,
style="underline",
),
justify="center"
)
console.line()
console.print(
Text(
"This is a bold italic gradient.",
style="bold italic",
),
justify="center"
)
console.line()
Wrap Any Rich Renderable
Use Gradient when you want to paint across an existing Rich renderable, such
as Markdown, a table, a layout, or a standard Rich panel.
from rich.console import Console
from rich.markdown import Markdown
from rich_gradient import Gradient
console = Console()
console.print(
Gradient(
Markdown("## Renderables\n\n- Text\n- Panels\n- Markdown"),
colors=["#38bdf8", "#a855f7", "#f97316"],
bg_colors=["#0f172a", "#1f2937"],
justify="center",
)
)
Background Gradients
Pass bg_colors to Text, Gradient, Panel, Rule, or Markdown to apply
background color stops. A single background color is treated as a solid fill;
multiple stops interpolate across the rendered output.
from rich_gradient import Text
Text(
"Foreground and background gradient",
colors=["#f8fafc", "#a7f3d0"],
bg_colors=["#0f172a", "#1e293b"],
)
Markdown
Use Markdown for a Rich Markdown renderable with the same gradient controls
as Gradient.
from rich.console import Console
from rich_gradient import Markdown
console = Console()
console.print(
Markdown(
"# Gradient Markdown\n\nSupports **Rich Markdown** content.",
colors=["cyan", "magenta", "gold1"],
)
)
CLI
This package no longer ships a command-line interface. Install
rich-gradient-cli for
terminal commands that build on the renderables provided here.
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.12.tar.gz.
File metadata
- Download URL: rich_gradient-0.3.12.tar.gz
- Upload date:
- Size: 17.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"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 |
d734630d7abb4e0051e0045915b1f107d53203340cad267f9e0d09af92aad088
|
|
| MD5 |
0a41506d73352b7789cc8473a3c1d3c4
|
|
| BLAKE2b-256 |
9191bd91c84aa574cea11def5a9c61d20c1f5114253252faff721e145fc00b04
|
File details
Details for the file rich_gradient-0.3.12-py3-none-any.whl.
File metadata
- Download URL: rich_gradient-0.3.12-py3-none-any.whl
- Upload date:
- Size: 57.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"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 |
d4e75195c991844fa40d8457088e20c666f1e30e4673affce0dc78899e6f7ba9
|
|
| MD5 |
8fd3a724b7960d9af4c2eaa7c499861a
|
|
| BLAKE2b-256 |
3b083709cc735c4e739b75f6edf7010fdba89ac8d8b5185a0d3d8c5085f6d87d
|