Colour (Simple Color Manipulation)
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
- breaking There is a significant naming conflict with the actively developed 'Colour Science for Python' library, which uses the package name `colour-science` but also commonly imports as `import colour`. Installing both `colour` (this package) and `colour-science` can lead to import ambiguity (e.g., `from colour import Color` might resolve to the wrong library's `Color` class or not find it, depending on installation order and Python path).
- deprecated This `colour` library (version 0.1.5) has not been updated since 2017 and is likely not actively maintained. It may lack support for newer Python versions or modern color spaces/standards. Its functionality is basic compared to more advanced and maintained color libraries.
- gotcha The `Color` object's attributes like `rgb`, `hsl`, `hsv` return tuples of floats between 0 and 1. If you expect 0-255 integer values (common in some web/graphics contexts), you will need to scale them manually.
Install
-
pip install colour
Imports
- Color
from colour import Color
Quickstart
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}")