Text of docs.python.org › 3.16 › library › colorsys.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

colorsys — Conversions between color systems — Python 3.16.0a2 documentation

Navigation index modules | next | previous | Python » 3.16.0a2 documentation » The Python standard library » Multimedia Services » colorsys — Conversions between color systems | Theme | colorsys — Conversions between color systems ¶ Source code: Lib/colorsys.py The colorsys module defines bidirectional conversions of color values between colors expressed in the RGB (Red Green Blue) color space used in computer monitors and three other coordinate systems: YIQ, HLS (Hue Lightness Saturation) and HSV (Hue Saturation Value).

Coordinates in all of these color spaces are floating-point values. In the YIQ space, the Y coordinate is between 0 and 1, but the I and Q coordinates can be positive or negative. In all other spaces, the coordinates are all between 0 and 1. See also More information about color spaces can be found at https://www.poynton.ca/pdf/ColourFAQ.pdf and https://www.cambridgeincolour.com/tutorials/color-spaces.htm . The colorsys module defines the following functions: colorsys. rgb_to_yiq ( r , g , b ) ¶ Convert the color from RGB coordinates to YIQ coordinates. colorsys. yiq_to_rgb ( y , i , q ) ¶ Convert the color from YIQ coordinates to RGB coordinates. colorsys. rgb_to_hls ( r , g , b ) ¶ Convert the color from RGB coordinates to HLS coordinates. colorsys. hls_to_rgb ( h , l , s ) ¶ Convert the color from HLS coordinates to RGB coordinates. colorsys. rgb_to_hsv ( r , g , b ) ¶ Convert the color from RGB coordinates to HSV coordinates. colorsys. hsv_to_rgb ( h , s , v ) ¶ Convert the color from HSV coordinates to RGB coordinates.

Example: >>> import colorsys >>> colorsys . rgb_to_hsv ( 0.2 , 0.4 , 0.4 ) (0.5, 0.5, 0.4) >>> colorsys . hsv_to_rgb ( 0.5 , 0.5 , 0.4 ) (0.2, 0.4, 0.4) Previous topic wave — Read and write WAV files Next topic Internationalization This page Report a bug Improve this page Show source « Navigation index modules | next | previous | Python » 3.16.0a2 documentation » The Python standard library » Multimedia Services » colorsys — Conversions between color systems | Theme | © Copyright 2001 Python Software Foundation.

This page is licensed under the Python Software Foundation License Version 2. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License. See History and License for more information. The Python Software Foundation is a non-profit corporation. Please donate. Last updated on Nov 19, 2026 (21:38 UTC). Found a bug ? Created using Sphinx 9.1.1.