Tiny, zero-dependency color utilities: convert HEX/RGB to OKLCH, HSL, HSV, CMYK and check WCAG contrast. Powered by colorpicker.cx.
Project description
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})-> CSSoklch()stringto_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
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 colortools_cx-1.0.0.tar.gz.
File metadata
- Download URL: colortools_cx-1.0.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6a6939aeafaa312d3efbe8a442a3517a33aec3d92bb65cf3a70ca7bc9b6e3d4
|
|
| MD5 |
89515eb4599e1cf3bbb373c655078af4
|
|
| BLAKE2b-256 |
c719852a7e6656b5fa6a388d0dc2cf2db948a6f1b4dc1ac8ab03088fd0d405ed
|
File details
Details for the file colortools_cx-1.0.0-py3-none-any.whl.
File metadata
- Download URL: colortools_cx-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aacf09a745b5994e81a5cb07916cb216696fcf94c49d98f7df12dfa570dcc148
|
|
| MD5 |
2983f3344a21ad71a6596fe0d28538bf
|
|
| BLAKE2b-256 |
bb486a630ada1f3ecd759e424d189243ffa31f56bed40dc068435894ee3b3359
|