Utility functions for working with colors (conversion, manipulation, validation).
Project description
tintelligence-color-utils
Utility functions for working with colors: conversions, manipulations, family assignment, sorting, and optional Qt helpers.
Installation
pip install tintelligence-color-utils
Optional Qt support
If you need QColor helpers, install with one of the extras:
- PySide6:
pip install "tintelligence-color-utils[qt_pyside6]"
- PyQt6:
pip install "tintelligence-color-utils[qt_pyqt6]"
Quick start
from color_utils import hex_to_hsv, get_color_family
h, s, v = hex_to_hsv("#FF7F00")
print(h, s, v)
print(get_color_family(h, s, v))
API Reference
All functions are available from color_utils top-level import.
Conversion
hex_to_rgb(hex_code: str) -> tuple[float, float, float]- Convert
#RRGGBBorRRGGBBto an(r, g, b)tuple in[0, 1]. RaisesValueErroron invalid input.
- Convert
hex_to_hsv(hex_code: str) -> tuple[float, float, float]- Convert a hex color to HSV
(h, s, v)whereh ∈ [0,1].
- Convert a hex color to HSV
rgb_to_hex(r: int, g: int, b: int) -> str- Convert integer RGB (0-255) to
#RRGGBB.
- Convert integer RGB (0-255) to
hex_midpoint(c1: str | None, c2: str | None) -> str | None- Midpoint between two hex colors as
#RRGGBB. ReturnsNoneif inputs are invalid.
- Midpoint between two hex colors as
rgb_to_lab(r: int, g: int, b: int) -> tuple[float, float, float]- Approximate sRGB (D65) to CIE Lab* with
L ∈ [0..100].
- Approximate sRGB (D65) to CIE Lab* with
normalize_lab(l: float | None, a: float | None, b: float | None) -> tuple[float | None, float | None, float | None]- Normalize Lab to
[0,1]each.L/100, anda,bvia(v+128)/255when needed.
- Normalize Lab to
rgb_to_hsl(r: int, g: int, b: int) -> tuple[int, int, int]- Convert RGB (0-255) to HSL where
H ∈ [0..360],S,L ∈ [0..100](ints).
- Convert RGB (0-255) to HSL where
lab_to_lch(l: float, a: float, b: float) -> tuple[float, float, float]- Convert CIE Lab to LCH(ab)
(L, C, H_deg).
- Convert CIE Lab to LCH(ab)
brightness_from_hex(hex_color: str) -> float | None- Perceived brightness (Lab L) from a hex color. Higher means brighter.
Color families
get_color_family(hue: float, saturation: float, value: float) -> str- Assign a color family based on HSV, with handling for dark and muted tones. Families include e.g. "Black", "Grey", "White / Off-white", "Red", "Pink", "Orange", "Yellow", "Green", "Turquoise / Teal", "Blue", "Purple / Violet", "Brown", "Unknown".
Shades
get_darker_shades(hex_code: str, steps: int = 2, factor: float = 0.8) -> tuple[str, ...]- Generate
stepsdarker hex shades by multiplying V byfactoriteratively.
- Generate
Sorting
sort_paints_by_color(paints: list[dict], mode: str = "hue") -> list[dict]- Sort a list of paint dicts by
"hue","saturation", or"value". Expects a"color_primary"hex field.
- Sort a list of paint dicts by
sort_paints_by_family_value_hue(paints: list[dict]) -> list[dict]- Group by color family, then sort by value (desc) and hue (asc). Adds
_hsvand_familykeys to returned items.
- Group by color family, then sort by value (desc) and hue (asc). Adds
Qt helper (optional)
color_utils.qcolor.to_qcolor(color) -> QColor- Convert a hex string,
(r, g, b)tuple, orQColorinstance to aQColor. Requires PySide6, PyQt6, or aqt_core.QColorshim. RaisesRuntimeErrorif noQColoris available.
- Convert a hex string,
Development
- Python 3.9+
- Install dev deps:
pip install -e .[dev] - Build:
python -m build - Test:
pytest
License
MIT
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 tintelligence_color_utils-0.1.0.tar.gz.
File metadata
- Download URL: tintelligence_color_utils-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46b37d39cce86d2d35f268c808ec03be810589e9077a0563a72b551421a38cc9
|
|
| MD5 |
54d0f44ccce5bee287378e84320ca741
|
|
| BLAKE2b-256 |
a97de63aa0403b34b0d51ef45b8b72688e681207e3156cc1374d569f6305ca66
|
Provenance
The following attestation bundles were made for tintelligence_color_utils-0.1.0.tar.gz:
Publisher:
publish.yml on Tintelligence-App/color-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tintelligence_color_utils-0.1.0.tar.gz -
Subject digest:
46b37d39cce86d2d35f268c808ec03be810589e9077a0563a72b551421a38cc9 - Sigstore transparency entry: 494387508
- Sigstore integration time:
-
Permalink:
Tintelligence-App/color-utils@6c53364fda44eb526a177c440bd74390836efd97 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Tintelligence-App
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6c53364fda44eb526a177c440bd74390836efd97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tintelligence_color_utils-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tintelligence_color_utils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7beedddf22a8a6bda74db2427ae065706a5da297997b64acbddc50a94983513
|
|
| MD5 |
5eb870f77e35812441c0e782b048b44d
|
|
| BLAKE2b-256 |
5255715a3604643956809e86d16b487edabdb0f4b823bcd16b6c72b8b136d2ef
|
Provenance
The following attestation bundles were made for tintelligence_color_utils-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Tintelligence-App/color-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tintelligence_color_utils-0.1.0-py3-none-any.whl -
Subject digest:
b7beedddf22a8a6bda74db2427ae065706a5da297997b64acbddc50a94983513 - Sigstore transparency entry: 494387558
- Sigstore integration time:
-
Permalink:
Tintelligence-App/color-utils@6c53364fda44eb526a177c440bd74390836efd97 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Tintelligence-App
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6c53364fda44eb526a177c440bd74390836efd97 -
Trigger Event:
push
-
Statement type: