colorzero

Yet another Python color library


Keywords
color, python
License
BSD-3-Clause
Install
pip install colorzero==1.1

Documentation

lightwave

Lightwave is a color manipulation library for Python (yes, another one) which aims to be reasonably simple to use and "pythonic" in nature.

It does not aim to be as comprehensive, powerful, or that matter as correct as, say, colormath. Lightwave originally grew out of work on my picamera project, hence it's intended to be sufficiently simple that school children can use it without having to explain color spaces and illuminants. However, it does aim to be useful to a wide range of skills, hence it does include basic facilities for CIE Lab representations, and Delta-E calculations should you need them.

The major difference between lightwave and other libraries (grapefruit, colormath, etc.) is that its Color class is a namedtuple descendent. This means it is immutable; you cannot directly change the attributes of a Color instance. The major advantage of this is that instances can be used as keys in dictionaries, or placed in sets.

Manipulation of Color instances is done by typical operations with other classes the result of which is a new Color instance. For example:

>>> from lightwave import Color, Red
>>> c = Color('green')
>>> c
<Color html="#008000" rgb=(0.0, 0.5, 0.5)>
>>> c + Red(0.1)
<Color html="#198000" rgb=(0.1, 0.5, 0.0)>
>>> c += Red(0.1)
>>> c.hue
Hue(deg=108.046875)
>>> c.saturation
Saturation(1.0)
>>> c * Saturation(0.0)
<Color html="#404040" rgb=(0.25098, 0.25098, 0.25098)>

Links

  • The code is licensed under the BSD license
  • The source code can be obtained from GitHub, which also hosts the bug tracker
  • The documentation (which includes installation, quick-start examples, and lots of code recipes) can be read on ReadTheDocs
  • Packages can be downloaded from PyPI, but reading the installation instructions is more likely to be useful