Color Math and Conversion Library

3.0.0 · active · verified Thu Apr 16

colormath is a Python library that simplifies complex color mathematics and conversions. The current stable version is 3.0.0. It provides support for a wide range of color spaces (e.g., CIE Lab, XYZ, sRGB, HSL, HSV, CMY/CMYK), enabling conversions between them, calculation of color differences (Delta E), and chromatic adaptations. The project maintains an active status with ongoing documentation updates, though code releases are less frequent.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a LabColor object and convert it to the XYZColor space using the `convert_color` function.

from colormath.color_objects import LabColor, XYZColor
from colormath.color_conversions import convert_color

# Instantiate a CIE Lab color object
lab = LabColor(lab_l=50.0, lab_a=20.0, lab_b=-15.0)
print(f"Original LabColor: {lab}")

# Convert the Lab color to XYZ color space
xyz = convert_color(lab, XYZColor)
print(f"Converted XYZColor: {xyz}")

# You can access individual components
print(f"X coordinate: {xyz.xyz_x}")
print(f"Y coordinate: {xyz.xyz_y}")
print(f"Z coordinate: {xyz.xyz_z}")

view raw JSON →