colourings
A lightweight Python library for creating, converting, comparing and interpolating colours. No runtime dependencies, typed throughout.
This project is a modernized fork of vaab/colour with additional formats, typing, revised channel ranges, and updated packaging.
Install
pip install colourings
Minimal example
from colourings import Color
c = Color("red")
c.hsl # HSL(hue=0.0, saturation=100.0, lightness=50.0)
c.oklch # OKLCH(lightness=0.6279..., chroma=0.2576..., hue=29.2338...)
c.mix("white", 0.3).hex_l # '#ff7765'
c.contrast_ratio("white") # 3.9984...
c.best_text_color() # <Color black>
c.darken(0.2).nearest_name() # 'firebrick'
What it does
| 15 formats | rgb hsl hsv hex web xyz lab lch oklab oklch cmyk yuv and alpha variants, each readable and writable |
Creating colours |
| CSS Color 4 & 5 | rgb() hsl() lab() lch() oklab() oklch(), color-mix(), color() with display-p3 / a98-rgb / rec2020, plus to_css() output |
CSS syntax |
| Gradients | range_to and color_scale, interpolating in hsl lab lch oklab oklch, either way round the hue circle, alpha included |
Gradients |
| Adjustment | lighten darken saturate desaturate with absolute or relative steps, grayscale invert rotate_hue mix, and the hue harmonies |
Adjusting |
| WCAG contrast | contrast_ratio relative_luminance is_readable best_text_color is_dark |
Contrast |
| Perceptual distance | delta_e over CIE76, CIE94, CIEDE2000 and Oklab, and nearest_name |
Difference |
| Compositing | over and blend through all sixteen CSS blend modes, encoded or linear |
Compositing |
| Gamut checking | in_srgb_gamut, to ask before a value gets clipped |
Ranges and gamut |
| Stable picking | pick_for, mapping any object to the same colour in every process |
Equality and picking |
Correctness
Most of this library is arithmetic on published constants, and a wrong constant there does not raise — it returns a plausible colour that is simply wrong. So every constant is either quoted from a citable source or derived in exact arithmetic, and anything whose constants could not be confirmed raises instead of guessing.
CIEDE2000 is checked against all 34 pairs of the published Sharma–Wu–Dalal test data. The CSS wide-gamut matrices are each derived twice, independently. Coverage is 100% of statements and branches, and every example in the README and the docs is executed by the test suite with its claimed output checked.
Contributing
Bug reports, colour-science corrections and pull requests are welcome. CONTRIBUTING.md describes the checks CI runs, all of which you can run locally, and what a change needs before it can be merged.
Security
To report a vulnerability, use GitHub's private reporting rather than a public issue. SECURITY.md sets out what is in scope — the short version is that colourings performs no I/O, opens no network connections and has no runtime dependencies, which leaves crafted inputs and the release process itself.
License
BSD-3-Clause. See LICENSE.
Release files for colourings 2.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 | |
|---|---|---|---|
| colourings-2.0.0.tar.gz | 121.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| colourings-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 185.5 kB
Release files / colourings-2.0.0.tar.gz
| Download URL | colourings-2.0.0.tar.gz |
|---|---|
| Size | 121.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
022fdc05d4e875729564199fa662e0cca54e3f724fca98ed82f67c88c88b88ab
|
|
BLAKE2b-256 checksum How to use checksums |
477bb4b099e071bd73006dbf53246534a310c1a55583b2b8508585d2e9afb71d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / colourings-2.0.0-py3-none-any.whl
| Download URL | colourings-2.0.0-py3-none-any.whl |
|---|---|
| Size | 63.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
24ddfdb3b54fb2cb0073808777a9d8bd661daafc5f6e11cca1bd25d80f3fc699
|
|
BLAKE2b-256 checksum How to use checksums |
0188a4d087592a982147c632ae25260f43e3f609d475713a505daa74e47f925b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency log