Metadata-Version: 2.4
Name: colortools-cx
Version: 1.0.0
Summary: Tiny, zero-dependency color utilities: convert HEX/RGB to OKLCH, HSL, HSV, CMYK and check WCAG contrast. Powered by colorpicker.cx.
Project-URL: Homepage, https://colorpicker.cx
Project-URL: Color Picker, https://colorpicker.cx/color-picker
Project-URL: Color Converter, https://colorpicker.cx/converter
Project-URL: Repository, https://github.com/colorpickercx/colortools-cx
Author-email: ColorTools <giaanenlaetin@gmail.com>
License: MIT
License-File: LICENSE
Keywords: accessibility,cmyk,color,color-converter,color-picker,colortools,contrast,css,hex,hsl,image-color-picker,oklch,palette,rgb,wcag
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# 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](https://colorpicker.cx/color-picker) and
[color converter](https://colorpicker.cx/converter) at **[colorpicker.cx](https://colorpicker.cx)**.

## Install

```sh
pip install colortools-cx
```

## Usage

```python
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](https://colorpicker.cx)** — free, no signup.

## License

MIT (c) [ColorTools](https://colorpicker.cx)
