Colour (Simple Color Manipulation)

0.1.5 · maintenance · verified Sat Apr 11

The `colour` library, version 0.1.5, provides simple utilities for converting and manipulating various color representations such as HSL, RGB, web (hex), and X11 named colors. It offers a `Color` object for object-oriented manipulation and also exposes single-purpose conversion functions. This library is older and has a slow release cadence, with its last release in 2017.

Warnings

Install

Imports

Quickstart

Demonstrates creating `Color` objects, converting between color spaces (hex, RGB, HSL), and generating a simple color gradient.

from colour import Color

# Create a color object from a named color
red_color = Color("red")
print(f"Red color: {red_color}")

# Convert to different formats
print(f"Hex: {red_color.hex}")
print(f"RGB (0-1 tuple): {red_color.rgb}")
print(f"HSL (0-1 tuple): {red_color.hsl}")

# Create a color from RGB tuple
blue_color = Color(rgb=(0, 0, 1))
print(f"Blue color: {blue_color}")

# Generate a color gradient
yellow = Color("yellow")
colors = list(yellow.range_to(Color("purple"), 5))
print("Gradient from yellow to purple:")
for c in colors:
    print(f"- {c.hex}")

view raw JSON →