sunasty-color-math
Zero-dependency Python utility for sRGB, HSL, and OKLCH color space conversions, relative luminance, and WCAG 2.1 contrast calculation.
Originally developed for the Sunasty Color Picker client-side tool and the Sunasty Developer Toolkit.
Features
- sRGB & OKLCH: Fast, exact conversions using Björn Ottosson's Oklab matrices.
- WCAG 2.1 Conformance: Relative luminance calculation and contrast ratios from
1.0:1to21.0:1. - Zero Dependencies: Pure standard library, compatible with Python 3.8+.
Installation
pip install sunasty-color-math
Quick Start
from sunasty_color_math import hex_to_rgb, contrast_ratio, check_wcag, rgb_to_oklch
# Parse colors
teal = hex_to_rgb("#0F766E")
white = (255, 255, 255)
# Calculate WCAG contrast
ratio = contrast_ratio(teal, white)
print(f"Contrast ratio: {ratio}:1")
conformance = check_wcag(ratio)
print(f"Passes AA normal text: {conformance['aa_normal']}")
# Convert to OKLCH
l, c, h = rgb_to_oklch(*teal)
print(f"Lightness: {l}, Chroma: {c}, Hue: {h}°")
Related Tools
- Sunasty Color Picker & Palette Extractor
- Sunasty Developer Utilities
- Sunasty Color Picker Chrome Extension
License
MIT © Bastien Sulyan
Metadata
Release files for sunasty-color-math 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sunasty_color_math-1.0.0.tar.gz | 4.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sunasty_color_math-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / sunasty_color_math-1.0.0.tar.gz
| Download URL | sunasty_color_math-1.0.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f267c2102dd17e201a103d7277e6e47680116b2b778a5f458154a8b2b4be1b2
|
|
BLAKE2b-256 checksum How to use checksums |
a8f9edbc1931aa5c31924f63fae4ae365959df9d42729818bf920d3466d281e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / sunasty_color_math-1.0.0-py3-none-any.whl
| Download URL | sunasty_color_math-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ad25edd661fa3ec71e4c47143731d050aac7398535e4b07fb5824b49402d497
|
|
BLAKE2b-256 checksum How to use checksums |
f4dfab88275a9987334239a1d081023270d3215b102cc1573a3bf6838a3f3ce1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for sunasty-color-math 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.