That function expects decimal for s (saturation) and v (value), not percent. Divide by 100.

>>> import colorsys

# Using percent, incorrect
>>> test_color = colorsys.hsv_to_rgb(359,100,100)
>>> test_color
(100, -9900.0, -9900.0)

# Using decimal, correct
>>> test_color = colorsys.hsv_to_rgb(1,1,1)
>>> test_color
(1, 0.0, 0.0)

If you would like the non-normalized RGB tuple, here is a function to wrap the colorsys function.

def hsv2rgb(h,s,v):
    return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h,s,v))

Example functionality

>>> hsv2rgb(0.5,0.5,0.5)
(64, 128, 128)
Answer from Cory Kramer on Stack Overflow
Top answer
1 of 9
64

That function expects decimal for s (saturation) and v (value), not percent. Divide by 100.

>>> import colorsys

# Using percent, incorrect
>>> test_color = colorsys.hsv_to_rgb(359,100,100)
>>> test_color
(100, -9900.0, -9900.0)

# Using decimal, correct
>>> test_color = colorsys.hsv_to_rgb(1,1,1)
>>> test_color
(1, 0.0, 0.0)

If you would like the non-normalized RGB tuple, here is a function to wrap the colorsys function.

def hsv2rgb(h,s,v):
    return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h,s,v))

Example functionality

>>> hsv2rgb(0.5,0.5,0.5)
(64, 128, 128)
2 of 9
27

If you like performance, it's best to avoid imports and use your own optimized code

Here's GIMP's code ported to python, tested at 99% acuracy, and improved for performance:
(this code happens to match colorsys almost exactly)

scalar = float # a scale value (0.0 to 1.0)
def hsv_to_rgb( h:scalar, s:scalar, v:scalar, a:scalar ) -> tuple:
    if s:
        if h == 1.0: h = 0.0
        i = int(h*6.0); f = h*6.0 - i
        
        w = v * (1.0 - s)
        q = v * (1.0 - s * f)
        t = v * (1.0 - s * (1.0 - f))
        
        if i==0: return (v, t, w, a)
        if i==1: return (q, v, w, a)
        if i==2: return (w, v, t, a)
        if i==3: return (w, q, v, a)
        if i==4: return (t, w, v, a)
        if i==5: return (v, w, q, a)
    else: return (v, v, v, a)

output:

>>> hsv_to_rgb( 359/360.0, 1.0, 1.0, 1.0 )
(1.0, 0.0, 0.016666666666666607, 1.0)

Using an if-chain like above is actually faster than using elif

Using a wrapper, like in Cyber's answer, takes a few extra steps for the interpreter to perform.
To add, the for loop in Cyber's example is a real performance killer when used like that

If you want slightly more performance, simply do this:
(I won't say this is the best possible performance, but it's certainly better)

scalar = float # a scale value (0.0 to 1.0)
def hsv_to_rgb( h:scalar, s:scalar, v:scalar, a:scalar ) -> tuple:
    a = int(255*a)
    if s:
        if h == 1.0: h = 0.0
        i = int(h*6.0); f = h*6.0 - i
        
        w = int(255*( v * (1.0 - s) ))
        q = int(255*( v * (1.0 - s * f) ))
        t = int(255*( v * (1.0 - s * (1.0 - f)) ))
        v = int(255*v)
        
        if i==0: return (v, t, w, a)
        if i==1: return (q, v, w, a)
        if i==2: return (w, v, t, a)
        if i==3: return (w, q, v, a)
        if i==4: return (t, w, v, a)
        if i==5: return (v, w, q, a)
    else: v = int(255*v); return (v, v, v, a)

^ this guarantees int() output with a range of 255 (the input is still the same)

>>> hsv_to_rgb( 359/360.0, 1.0, 1.0, 1.0 )
(255, 0, 4, 255)

NOTE: this code tests just as accurate as colorsys to GIMP (99% correct):

TIP: stay away from 3rd-party where possible, try the direct approach if you can.
exculusions: compiled C extensions such as PIL or NumPy, or ctypes wrappers such as PyOpenGL (uses the DLL)

🌐
Python
docs.python.org › 3 › library › colorsys.html
colorsys — Conversions between color systems
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).
Discussions

Convert HSV to RGB
Hello developers, I have an HSV value (according to docs) which is [8.67, 0.98, 0.63] and I cant convert it to RGB which should be [208, 89, 24] import colorsys value_hsv = [8.67, 0.98, 0.63] value_rgb = colorsys.hsv_to_rgb(value_hsv[0], value_hsv[1], value_hsv[2]) print value_rgb[0]*255, ... More on tech-artists.org
🌐 tech-artists.org
0
0
December 15, 2020
Converting HSV to RGB in Python - Stack Overflow
27 Convert RGB values to equivalent HSV values using Python More on stackoverflow.com
🌐 stackoverflow.com
color - HSV to RGB conversion - Blender Stack Exchange
let's take the hsv color 0.4, 0.8, 1.0 everywhere I looked this converted to Hex 33FF85 - even in Blender when I convert it to RGB(using python colorsys, python Color from math, webservices), it ... More on blender.stackexchange.com
🌐 blender.stackexchange.com
Function to Convert HSV to RGB, for better looking random & gradient colors!
It turns out that the internal workings of Adobe Postscript use the same formula. This description explains the formula in a much different way, and I needed about two hours of work to verify that they are indeed the same. More on reddit.com
🌐 r/openscad
2
7
January 15, 2024
🌐
Medium
scriptopia-official.medium.com › python-colorsys-convert-hsv-to-rgb-aaf27ef40186
Python Colorsys — Convert HSV to RGB - Scriptopia Official Medium - Medium
January 1, 2024 - Moving on we use the colorsys.hsv_to_rgb() function to convert the HSV values to their corresponding RGB values. The RGB values are obtained, each value is multiplied by 255 (to scale the values back to the 0-255 range for RGB representation).
🌐
GitHub
gist.github.com › mathebox › e0805f72e7db3269ec22
Python methods to convert colors between RGB, HSV and HSL · GitHub
@mathebox & @ArtemBernatskyy, According to https://en.wikipedia.org/wiki/HSL_and_HSV, add l = (high + low) / 2, and not low. ... def clamp(value, min_value, max_value): return max(min_value, min(max_value, value)) def saturate(value): return clamp(value, 0.0, 1.0) def hue_to_rgb(h): r = abs(h * 6.0 - 3.0) - 1.0 g = 2.0 - abs(h * 6.0 - 2.0) b = 2.0 - abs(h * 6.0 - 4.0) return saturate(r), saturate(g), saturate(b) def hsl_to_rgb(h, s, l): r, g, b = hue_to_rgb(h) c = (1.0 - abs(2.0 * l - 1.0)) * s r = (r - 0.5) * c + l g = (g - 0.5) * c + l b = (b - 0.5) * c + l return r, g, b
🌐
GeeksforGeeks
geeksforgeeks.org › python › matplotlib-colors-hsv_to_rgb-in-python
Matplotlib.colors.hsv_to_rgb() in Python - GeeksforGeeks
July 12, 2025 - Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. The matplotlib.colors.hsv_to_rgb() function is used to convert hsv values to rgb.
Find elsewhere
🌐
Esri Community
community.esri.com › t5 › geoprocessing-questions › arcgis-python-hsv-to-rgb-colour-conversion › td-p › 1381428
ArcGIS python HSV to RGB colour conversion - Esri Community
May 8, 2026 - def colourHSVtoRGB(self,H,S,V): # The ArcGIS HSV model is strange - Hue 0-240, Saturation 0 - 255, Value 0 - 255 from matplotlib.colors import hsv_to_rgb # Convert hval to 360 and make it 0 - 1 hval = 3.6 * (H / 240) sval = S / 255 vval = V / 255 invals = [hval, sval, vval] rg = hsv_to_rgb(invals) R = rg[0] G = rg[1] B = rg[2] # Convert to 0 - 255 R = int(round((R * 255), 0)) G = int(round((G * 255), 0)) B = int(round((B * 255), 0))
🌐
Bobby Hadz
bobbyhadz.com › blog › python-convert-hsv-color-to-rgb
How to convert an HSV color to RGB in Python [4 Ways] | bobbyhadz
April 13, 2024 - Use the colorsys.hsv_to_rgb() method to convert an HSV color to RGB in Python.
🌐
PyPI
pypi.org › project › HSV
HSV · PyPI
November 1, 2021 - from HSV.hsv import rgb_to_hsv, hsv_to_rgb if __name__ == '__main__': ONE_255 = 1.0 / 255.0 r, g, b = 25, 60, 128 print("\nOriginal RGB values (R:%s, G:%s, B:%s)\n" % (r, g, b)) h, s, v = rgb_to_hsv(r * ONE_255, g * ONE_255, b * ONE_255) print("HSV values (H:%s, S:%s, V:%s)" % (h * 360.0, s * 100.0, v * 100.0)) r, g, b = hsv_to_rgb(h, s, v) print("Retrieved RGB values (R:%s, G:%s, B:%s)\n" % (r * 255.0, g * 255.0, b * 255.0)) If you need to compile the Cython code after changing the files hsv.pyx or hsv.pxd or the external C code please proceed as follow: 1) open a terminal window 2) Go in the
🌐
Top Tech Boy
toptechboy.com › convert-hsv-to-rgb-in-micropython
Convert HSV to RGB in Micropython | Technology Tutorials
To make this a library, we save it as h2RGB.py on our Raspberry Pi Pico W. You can save it either in the same folder your main programs are in, or in the lib folder. To use the library, then simply import the file (h2RGB) and call the method h2RGB.getRGB(degrees), where degrees is the point ...
🌐
Tech-Artists.Org
tech-artists.org › t › convert-hsv-to-rgb › 13390
Convert HSV to RGB - python - Tech-Artists.Org
December 15, 2020 - Hello developers, I have an HSV ... import colorsys value_hsv = [8.67, 0.98, 0.63] value_rgb = colorsys.hsv_to_rgb(value_hsv[0], value_hsv[1], value_hsv[2]) print value_rgb[0]*255, ......
🌐
Quora
quora.com › How-do-I-convert-a-color-value-from-HSV-to-RGB-in-OpenCV-Python
How to convert a color value from HSV to RGB in OpenCV Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Tool Checking
toolchecking.com › home › hsv to rgb
HSV to RGB Conversion Guide: Models, Differences & Tools
August 10, 2026 - Adjust RGB using m = V − C. Multiply R, G, B by 255 for final output. This process is often automated using software or libraries. Python, for instance, provides a simple colorsys.hsv_to_rgb() function to convert HSV to RGB easily.
🌐
SunFounder
docs.sunfounder.com › projects › kepler-kit › en › latest › video_course › lesson34.html
Lesson 34: Convert HSV to RGB in Micropython — SunFounder Kepler Kit for Raspberry Pi Pico W 1.0 documentation
Algorithm Development: Creates a function to convert HSV to RGB values and sets up the RGB LED with PWM on the Raspberry Pi Pico W. Code Implementation: Walkthrough of Python code for PWM control and HSV to RGB conversion, including a library function.
🌐
Reddit
reddit.com › r/openscad › function to convert hsv to rgb, for better looking random & gradient colors!
r/openscad on Reddit: Function to Convert HSV to RGB, for better looking random & gradient colors!
January 15, 2024 -

Is color little pointless in OpenSCAD? Sure, maybe.. But it could also be the thing that makes your project preview visually stand out!

Problem is, if you've ever tried to do random or incremental gradient colors using RGB, it can often produces jarring, pale, or otherwise ugly color combinations. This is where HSV color format comes in handy. By specifying colors in HSV (Hue 0-360, Saturation 0-1, Value 0-1), you can get nice looking random or gradient colors every time.

Anyway, with the help of GPT-4, I converted a Python function I frequently use for HSV, into an OpenSCAD function! And it seems to work great, so I figured I'd share here. ;)

// Function to convert HSV color input to RGB output
function hsv2rgb(h, s=1, v=1) = let(
    h = h / 360,
    i = floor(h * 6),
    f = h * 6 - i,
    p = v * (1 - s),
    q = v * (1 - f * s),
    t = v * (1 - (1 - f) * s)
) i % 6 == 0 ? [v, t, p] :
  i == 1 ? [q, v, p] :
  i == 2 ? [p, v, t] :
  i == 3 ? [p, q, v] :
  i == 4 ? [t, p, v] :
           [v, p, q];

Save as hsv2rgb.scad so you can easily reuse in other scripts via use <hsv2rgb.scad>

Here's an example of what you can do with it: https://i.imgur.com/gjzDFqL.png

And the code for that example:

use <hsv2rgb.scad>

for(i=[0:18:360]){
  color(hsv2rgb(i, 1, 1))
    rotate([0,0,i]) translate([-40,0,0]) scale([4,1.1,1])
      cylinder(1,d=20,$fn=3);
}

text = "HSV in OpenSCAD!";
for (i = [0:len(text)-1]) {
  color(hsv2rgb(floor(i/len(text)*360)))
    translate([i*8-len(text)*8/2,70,1]) rotate([90,0,0])
      linear_extrude(2)
        text(text[i],font="DejaVu Sans Mono");
}

Edit: Woops.. I just found out BOSL2 contains similar functionality. So now I feel a little silly. Oh well, still a neat compact function.

🌐
GitHub
github.com › TheAlgorithms › Python › blob › master › conversions › rgb_hsv_conversion.py
Python/conversions/rgb_hsv_conversion.py at master · TheAlgorithms/Python
def rgb_to_hsv(red: int, green: int, blue: int) -> list[float]: """ Conversion from the RGB-representation to the HSV-representation. The tested values are the reverse values from the hsv_to_rgb-doctests. Function "approximately_equal_hsv" is needed because of small deviations due to ·