How set Hex in RGB Node? (Python)
Hex values are interpreted in the sRGB color space, while Blender uses a linear RGB color space internally.  The conversion functions can be found on the sRGB Wikipedia page.  The hex channel values themselves (0-255) should be divided by 255 before application of the formulas.  A pure Python implementation looks like this:

def srgb_to_linearrgb(c):
    if   c &lt; 0:       return 0
    elif c &lt; 0.04045: return c/12.92
    else:             return ((c+0.055)/1.055)**2.4

def hex_to_rgb(h,alpha=1):
    r = (h &amp; 0xff0000) &gt;&gt; 16
    g = (h &amp; 0x00ff00) &gt;&gt; 8
    b = (h &amp; 0x0000ff)
    return tuple([srgb_to_linearrgb(c/0xff) for c in (r,g,b)] + [alpha])


and using it like so:

bpy.data.materials["Material"].node_tree.nodes["RGB"].outputs[0].default_value = \
    hex_to_rgb(0x123456)


seems to work correctly.