Stdlib-only color palettes and format converters — ANSI, hex, RGB, HSL, WCAG contrast, color-blind safe variants.
Project description
codechu-color
Stdlib-only color palettes and format converters for Python 3.10+. Zero runtime dependencies.
Solves the cross-surface palette drift problem: CLI tools work in
ANSI escapes, GTK apps work in hex / CSS, JSON exports want flat
dicts. codechu-color keeps one source of truth and derives the rest.
Install
pip install codechu-color
Quick start
from codechu_color import Color, Palette, RISK, palette_for, to_gtk_css
# Single color in every form
green = Color.from_hex("#1a7f37", name="low")
green.rgb # (26, 127, 55)
green.ansi_fg # "\x1b[32m"
green.ansi_bg # "\x1b[42m"
# Built-in semantic palette (GitHub accessibility-tuned)
RISK.low.hex # "#1a7f37"
RISK.high.hex # "#cf222e"
# Color-blind safe variants (Bang & Wong 2011)
pal = palette_for("risk", profile="deuteranopia")
pal.high.hex # "#d55e00" (vermilion, safe for red-green confusion)
# Export for GTK CSS
css = to_gtk_css(RISK, prefix="risk-")
# .risk-low { color: #1a7f37; } ...
# Flat dict for JSON
RISK.to_dict() # {"low": "#1a7f37", "medium": "#9a6700", "high": "#cf222e"}
WCAG helpers
from codechu_color import contrast_ratio, pick_text_color
contrast_ratio((255, 255, 255), (0, 0, 0)) # 21.0 (max)
pick_text_color((9, 105, 218)) # (255, 255, 255) — white on blue
Built-in palettes
| name | keys |
|---|---|
RISK |
low, medium, high |
TERMINAL |
basic ANSI 8 |
MATERIAL |
Material Design Primary 500 tones |
SOLARIZED_LIGHT / SOLARIZED_DARK |
full accent ramp + base tones |
Vision profiles
palette_for("risk", profile=...) accepts:
"default"— GitHub semantic green / amber / red"protanopia"— safe for protan red-blindness"deuteranopia"— safe for deutan red-green confusion (most common)"tritanopia"— safe for tritan blue-yellow confusion
Profiles use the Bang & Wong (2011) qualitative palette (Nature Methods 8: 441).
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 codechu_color-0.1.0.tar.gz.
File metadata
- Download URL: codechu_color-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39b0e59e4ce821b9bbe1ebc3b8555d5c3fb35072cbb810d4c81cc2bb7caf940f
|
|
| MD5 |
b9471c7b1f8fe49c6723e6c71dc18175
|
|
| BLAKE2b-256 |
fdfeeb0b4c526cc2d90e170327e560f9bb0cb506efb2ac962fc42d7ad5e0cbf6
|
Provenance
The following attestation bundles were made for codechu_color-0.1.0.tar.gz:
Publisher:
release.yml on codechu/color-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codechu_color-0.1.0.tar.gz -
Subject digest:
39b0e59e4ce821b9bbe1ebc3b8555d5c3fb35072cbb810d4c81cc2bb7caf940f - Sigstore transparency entry: 1582279371
- Sigstore integration time:
-
Permalink:
codechu/color-py@2ed755ded441252bba563de95cb70ca0a163071b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/codechu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2ed755ded441252bba563de95cb70ca0a163071b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file codechu_color-0.1.0-py3-none-any.whl.
File metadata
- Download URL: codechu_color-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60e360931fb023f76bec03b8f8e6992a6bba02b999251291ec1d40f6bc2675fb
|
|
| MD5 |
b0958241da3aa03f723c26518381d168
|
|
| BLAKE2b-256 |
160c9a2290cecd590c5007eea10b4d4d81b51a5d2e3d24e7d61714b55097edb1
|
Provenance
The following attestation bundles were made for codechu_color-0.1.0-py3-none-any.whl:
Publisher:
release.yml on codechu/color-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codechu_color-0.1.0-py3-none-any.whl -
Subject digest:
60e360931fb023f76bec03b8f8e6992a6bba02b999251291ec1d40f6bc2675fb - Sigstore transparency entry: 1582279508
- Sigstore integration time:
-
Permalink:
codechu/color-py@2ed755ded441252bba563de95cb70ca0a163071b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/codechu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2ed755ded441252bba563de95cb70ca0a163071b -
Trigger Event:
workflow_dispatch
-
Statement type: