Skip to main content

Extend Rich with the ability to parse CSS color names and 3-digit hex colors.

Project description

rich-color-ext

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).

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"
)

example

rich-gradient by Max Ludden

Packaging with PyInstaller

When bundling the project with PyInstaller you must include the JSON resource colors.json so it is available at runtime inside the bundle. There are two simple ways to do this.

  1. Pass the file with the command-line option --add-data:

    • macOS / Linux (colon separator):

      pyinstaller --onefile --add-data "src/rich_color_ext/colors.json:rich_color_ext" your_entry_script.py
      
    • Windows (semicolon separator):

      pyinstaller --onefile --add-data "src\\rich_color_ext\\colors.json;rich_color_ext" your_entry_script.py
      
  2. Add the file to the spec file's Analysis.datas list. Example snippet to paste into your .spec file:

    a = Analysis(
            ['your_entry_script.py'],
            pathex=[],
            binaries=[],
            datas=[('src/rich_color_ext/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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rich_color_ext-0.1.6.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rich_color_ext-0.1.6-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file rich_color_ext-0.1.6.tar.gz.

File metadata

  • Download URL: rich_color_ext-0.1.6.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for rich_color_ext-0.1.6.tar.gz
Algorithm Hash digest
SHA256 d58bbbcee95a52d0e32d06cd805789102fb59105ed4190d9a3613c56ae797cb4
MD5 be8f1f52a5c13d8547c01514967dfaec
BLAKE2b-256 94fc9b7408449bf82a7a14e468108e3738a0d50759d5b5f4029ef09265c932d9

See more details on using hashes here.

File details

Details for the file rich_color_ext-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for rich_color_ext-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 afe030d6d1857ec70261f576b1ce4eb81f3528c863f5ddfd5bf5d985da831b6a
MD5 6d123bda83150f7995d6cb8a29ad34eb
BLAKE2b-256 699903e1b8ee553b255a99d1073f6f14400c047c2f8d21290d44cf323090ccf3

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