Skip to main content

colortools-cx

Tiny, zero-dependency color utilities for Python: convert HEX/RGB to OKLCH, HSL, HSV, CMYK and check WCAG contrast — the same math that powers the free color picker and color converter at colorpicker.cx.

Install

pip install colortools-cx

Usage

from colortools_cx import hex_to_oklch, format_oklch, to_all_formats, contrast_ratio

format_oklch(hex_to_oklch("#ff0000"))
# 'oklch(62.8% 0.2577 29.23)'

to_all_formats("#5B7CFA")
# {'hex': '#5B7CFA', 'rgb': 'rgb(91, 124, 250)',
#  'hsl': 'hsl(227.55, 94.08%, 66.86%)', 'hsv': 'hsv(227.55, 63.6%, 98.04%)',
#  'cmyk': 'cmyk(63.6%, 50.4%, 0%, 1.96%)', 'oklch': 'oklch(62.74% 0.191 269.21)'}

contrast_ratio("#FDF0D5", "#003049")
# 12.25  (passes WCAG AA & AAA)

API

  • hex_to_oklch(hex) -> {l, c, h}
  • rgb_to_oklch(r, g, b) -> {l, c, h}
  • format_oklch({l, c, h}) -> CSS oklch() string
  • to_all_formats(hex) -> {hex, rgb, hsl, hsv, cmyk, oklch}
  • contrast_ratio(fg, bg) -> WCAG 2.1 ratio (1-21)
  • parse_hex(hex) -> (r, g, b) or (r, g, b, a)

Interactive version

Pick colors from an image, build palettes and CSS gradients, and check contrast in the browser at colorpicker.cx — free, no signup.

License

MIT (c) ColorTools

Metadata

Release files for colortools-cx 1.0.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 colortools-cx 1.0.0
File Size Uploaded
colortools_cx-1.0.0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colortools-cx 1.0.0
File Interpreter ABI Platform
colortools_cx-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.4 kB

Release files / colortools_cx-1.0.0.tar.gz

Download URL colortools_cx-1.0.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f6a6939aeafaa312d3efbe8a442a3517a33aec3d92bb65cf3a70ca7bc9b6e3d4
BLAKE2b-256 checksum
How to use checksums
c719852a7e6656b5fa6a388d0dc2cf2db948a6f1b4dc1ac8ab03088fd0d405ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / colortools_cx-1.0.0-py3-none-any.whl

Download URL colortools_cx-1.0.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aacf09a745b5994e81a5cb07916cb216696fcf94c49d98f7df12dfa570dcc148
BLAKE2b-256 checksum
How to use checksums
bb486a630ada1f3ecd759e424d189243ffa31f56bed40dc068435894ee3b3359
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

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