Skip to main content

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

Metadata

Release files for codechu-color 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codechu-color 0.1.0
File Size Uploaded
codechu_color-0.1.0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codechu-color 0.1.0
File Interpreter ABI Platform
codechu_color-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / codechu_color-0.1.0.tar.gz

Download URL codechu_color-0.1.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
39b0e59e4ce821b9bbe1ebc3b8555d5c3fb35072cbb810d4c81cc2bb7caf940f
BLAKE2b-256 checksum
How to use checksums
fdfeeb0b4c526cc2d90e170327e560f9bb0cb506efb2ac962fc42d7ad5e0cbf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 20, 2026.

Transparency log

Release files / codechu_color-0.1.0-py3-none-any.whl

Download URL codechu_color-0.1.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60e360931fb023f76bec03b8f8e6992a6bba02b999251291ec1d40f6bc2675fb
BLAKE2b-256 checksum
How to use checksums
160c9a2290cecd590c5007eea10b4d4d81b51a5d2e3d24e7d61714b55097edb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page