Extend Rich with the ability to parse CSS color names and 3-digit hex colors.
Project description
rich-color-ext extends the great rich library to be able to parse 3-digit hex colors (ie. #09F) and CSS color names (ie. rebeccapurple).
Latest release:
v0.1.9(2025-11-19). See the changelog for the full list of updates and run the command below to confirm which version is installed locally.
python -c "import rich_color_ext; print(rich_color_ext.__version__)"
Installation
uv (recommended)
# via uv directly
uv add rich-color-ext
or
# or via pip through uv
uv pip add rich-color-ext
pip
pip install rich-color-ext
Usage
To make use of rich-color-ext all you need to do is import and install it at the start of your program:
from rich_color_ext import install
from rich.console import Console
install() # Patch Rich's Color.parse method
console = Console(width=64)
console.print(
Panel(
"This is the [b #00ff99]rich_color_ext[/b #00ff99] \
example for printing CSS named colors ([bold rebeccapurple]\
rebeccapurple[/bold rebeccapurple]), 3-digit hex \
colors ([bold #f0f]#f0f[/bold #f0f]), and [b #99ff00]\
rich.color_triplet.ColorTriplet[/b #99ff00] & [b #00ff00]\
rich.color.Color[/b #00ff00] instances.",
padding=(1,2)
),
justify="center"
)
Logging
This package uses loguru for internal, developer-focused logging. By default the
logger is disabled so importing the package is quiet during normal usage. If you
need to enable internal debug output for troubleshooting, you can enable the
logger at runtime. For example:
from rich_color_ext import log
# Enable internal logging emitted by rich-color-ext (useful for debugging)
log.enable("rich_color_ext")
# Revert to disabled state
log.disable("rich_color_ext")
Note: loguru is used only for internal diagnostics and is not required at
runtime for the library's primary functionality; it is disabled by default to
avoid noisy output.
Packaging with PyInstaller
As of recent releases the CSS colour map is embedded in the Python package and a separate colors.json file is not required for normal usage. The library and CLI prefer the package-level get_css_map() function, so PyInstaller bundles typically do not need any extra data files.
If you are building or packaging an older distribution that expects a
standalone colors.json file, or you intentionally rely on shipping the JSON resource, include it in the bundle using the legacy approaches below.
-
Pass the file with the command-line option
--add-data:-
macOS / Linux (colon separator):
pyinstaller --onefile --add-data "static/json/colors.json:rich_color_ext" your_entry_script.py
-
Windows (semicolon separator):
pyinstaller --onefile --add-data "static\\json\\colors.json;rich_color_ext" your_entry_script.py
-
-
Add the file to the spec file's
Analysis.dataslist. Example snippet to paste into your.specfile:a = Analysis( ['your_entry_script.py'], pathex=[], binaries=[], datas=[('static/json/colors.json', 'rich_color_ext')], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None, )
Helper script
A small helper script is provided to build with PyInstaller and automatically choose the correct data separator for your platform. By default it builds the example src/rich_color_ext/cli.py entry script but you can pass any entry script as the first argument.
Usage:
./scripts/pyinstaller_build.sh [path/to/your_entry_script.py] # src/rich_color_ext/cli.py
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_color_ext-0.1.9.tar.gz.
File metadata
- Download URL: rich_color_ext-0.1.9.tar.gz
- Upload date:
- Size: 2.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"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 |
d32393b8e29bfc2add3eb89ffae26fe683f388325ea51461c1889a53e7f6d371
|
|
| MD5 |
0d1607847deed4117ab81ab6d63bf521
|
|
| BLAKE2b-256 |
88a2ba3dfff54c51ccce1304cd3315a1861c67e2142db2e9a778ef0bb11ab4b1
|
File details
Details for the file rich_color_ext-0.1.9-py3-none-any.whl.
File metadata
- Download URL: rich_color_ext-0.1.9-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"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 |
7005f871792f68cc188751d68bfc1e401456c46336103760a5eedba27048bc82
|
|
| MD5 |
05c7872b57a41b6683d52c7dd776c702
|
|
| BLAKE2b-256 |
5d9cbbc2f72e407d9457f4b9ae2165c05c4474dd5570dd4043603656269a6fad
|