Metadata-Version: 2.5
Name: wearton-colors
Version: 0.1.0
Summary: Small colour helpers: hex, RGB and HSL conversion and WCAG contrast. No dependencies.
Project-URL: Homepage, https://wearton.app/?utm_source=pypi&utm_medium=package&utm_campaign=launch
Project-URL: Made by, https://wearton.app
Project-URL: GitHub, https://github.com/wearton
Project-URL: Hugging Face, https://huggingface.co/wearton-app
Author-email: Wearton <admin@wearton.app>
License-Expression: MIT
License-File: LICENSE
Keywords: color,colour,contrast,hex,hsl,rgb,wcag
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Graphics
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# wearton-colors

Small colour helpers for Python: convert between hex, RGB and HSL, and check WCAG contrast. No dependencies, Python 3.9+.

```
pip install wearton-colors
```

```python
from wearton_colors import hex_to_rgb, rgb_to_hsl, contrast_ratio, readable_text_color

hex_to_rgb("#1e90ff")              # (30, 144, 255)
rgb_to_hsl((30, 144, 255))         # (209.6, 100.0, 55.9)
contrast_ratio("#777777", "#fff")  # 4.48 (WCAG AA needs 4.5 for body text)
readable_text_color("#000080")     # '#ffffff'
```

| Function | Does |
|---|---|
| `hex_to_rgb(value)` | `'#1e90ff'`, `'1e90ff'` or `'#19f'` to an `(r, g, b)` tuple |
| `rgb_to_hex(rgb)` | `(r, g, b)` to `'#rrggbb'` |
| `rgb_to_hsl(rgb)` / `hsl_to_rgb(hsl)` | RGB to and from hue 0-360, saturation and lightness 0-100 |
| `relative_luminance(rgb)` | WCAG 2.x relative luminance, 0 to 1 |
| `contrast_ratio(a, b)` | WCAG contrast ratio of two colours, 1 to 21 |
| `readable_text_color(background)` | black or white, whichever reads better on the background |

Run the tests: `python -m unittest discover -s tests`

## About

Made by [Wearton](https://wearton.app/?utm_source=pypi&utm_medium=package&utm_campaign=launch): a personal AI stylist that finds your colour season from one selfie, keeps your closet and tells you what to wear today. iPhone, Android, web, Chrome, Edge, Firefox, Safari, ChatGPT and Claude.

Wearton elsewhere: [GitHub](https://github.com/wearton) · [Hugging Face](https://huggingface.co/wearton-app) · [GitLab](https://gitlab.com/wearton) · [Docker Hub](https://hub.docker.com/u/wearton) · [DEV](https://dev.to/wearton)

License: MIT
