Skip to main content

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


Download files

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

Source Distribution

codechu_color-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

codechu_color-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

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

Hashes for codechu_color-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39b0e59e4ce821b9bbe1ebc3b8555d5c3fb35072cbb810d4c81cc2bb7caf940f
MD5 b9471c7b1f8fe49c6723e6c71dc18175
BLAKE2b-256 fdfeeb0b4c526cc2d90e170327e560f9bb0cb506efb2ac962fc42d7ad5e0cbf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_color-0.1.0.tar.gz:

Publisher: release.yml on codechu/color-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for codechu_color-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60e360931fb023f76bec03b8f8e6992a6bba02b999251291ec1d40f6bc2675fb
MD5 b0958241da3aa03f723c26518381d168
BLAKE2b-256 160c9a2290cecd590c5007eea10b4d4d81b51a5d2e3d24e7d61714b55097edb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_color-0.1.0-py3-none-any.whl:

Publisher: release.yml on codechu/color-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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