Not created again already exists material I have a such a code
    for image in bpy.data.images:
        if image.users:
            continue
        bpy.data.images.remove(image)
    mat = bpy.data.materials.get(&quot;Material&quot;)
    if mat is True:                
        mat.use_nodes=False   
        bpy.context.active_object.data.materials.delete(bpy.data.materials['Material'])                                 
    if mat is None:
    # create material
        mat = bpy.data.materials.new(name=&quot;Material&quot;)
    mat.use_nodes=True
    nodes=mat.node_tree.nodes
    for node in nodes:
        nodes.remove(node)    
    principledBDSF = nodes.new(type='ShaderNodeBsdfPrincipled') 
    principledBDSF.inputs[0].default_value = 0.8, 0.11, 0.02, 1
    principledBDSF.inputs[4].default_value = 0.5    
    principledBDSF.inputs[5].default_value = 0.45 
    principledBDSF.inputs[7].default_value = 0.35                     
    LCAoutput = nodes.new(type='ShaderNodeOutputMaterial') 
    LCAoutput.location = 300,0    
    links = mat_LCA.node_tree.links
    link = links.new(principledBDSF.outputs[0], LCAoutput.inputs[0])                      
    bpy.context.active_object.data.materials.append(bpy.data.materials['Material'])

When I run this function, I create material, but when I run it again, this material is created again. I am curious how to make the material not created as it already exists.
Greets
A material never is True.
Use if mat: which is boolean true if not None  Using if mat is True:  for a material will never be true.
Since you are setting use nodes later can also do this
mat = materials.get(&quot;Foo&quot;) or materials.new(&quot;Foo&quot;)

To drill this in here is a simple example
import bpy

context = bpy.context

def main(context):
    mat = bpy.data.materials.get(&quot;Foo&quot;)
    if mat:
        print(&quot;Material Foo exists, skipping&quot;)
        return 
    else:
        mat = bpy.data.materials.new(&quot;Foo&quot;)
        print(&quot;Created Material Foo&quot;)
        # do something with new material
        
    return

# test calls

main(context)
main(context)
main(context)

Output from default file no material &quot;Foo&quot;
Created Material Foo
Material Foo exists, skipping
Material Foo exists, skipping