Blender 2.8 (python) - How to set material color using hex value instead of RGB
You can convert a hex value to rgb like below, using shift and bitwise and operator, then divide it by 255 to get a value between 0 and 1.

import bpy

def hex_to_rgb( hex_value ):
    b = (hex_value &amp; 0xFF) / 255.0
    g = ((hex_value &gt;&gt; 8) &amp; 0xFF) / 255.0
    r = ((hex_value &gt;&gt; 16) &amp; 0xFF) / 255.0
    return r, g, b

def add_material(obj, material_name, h):
    material = bpy.data.materials.get(material_name)
    if material is None:
        material = bpy.data.materials.new(material_name)
    material.use_nodes = True
    principled_bsdf = material.node_tree.nodes['Principled BSDF']
    if principled_bsdf is not None:
        principled_bsdf.inputs[0].default_value = (*hex_to_rgb(h), 1)  
    obj.active_material = material

h = 0xE7E7FF

obj = bpy.context.object

add_material( obj, "test", h )


Note: you won't obtain the same value in the UI as the hex value is shown gamma corrected.