How to make node group of an existing material into a new group? (in python)
I have one method May be this is what you wan't this may work for you
if you do not wan't to use bpy.ops. .... then you have to create a node group

import bpy

for mat in bpy.data.materials:
    if "Material" in mat.name:
        nodes = mat.node_tree.nodes
        for node in nodes:
            if node.type != 'OUTPUT_MATERIAL':  # skip the material output node as we'll need it later
                nodes.remove(node)
group = bpy.data.node_groups.new(type="ShaderNodeTree", name="Test Group")


#Creating Group Input
group.inputs.new("NodeSocketShader", "Input1")
group.inputs.new("NodeSocketShader", "Input2")
input_node = group.nodes.new("NodeGroupInput")
input_node.location = (0, 0)

#Setting Default Values For Node Sockets

group.inputs[0].default_value = (1.000)
group.inputs[1].default_value = (2.000)

#Creating Group Output
group.outputs.new("NodeSocketShader", "Output1")
group.outputs.new("NodeSocketShader", "Output2")
output_node = group.nodes.new("NodeGroupOutput")
output_node.location = (500, 0)


# Creating Principled bsdf Node
#You can create any node here which you think are required to be in the group as these will be created automatically in a group

Principled_Bsdf_node = group.nodes.new('ShaderNodeBsdfPrincipled')
Principled_Bsdf_node.location = (100, 0)


#creating links between nodes in group
group.links.new(input_node.outputs["Input1"], Principled_Bsdf_node.inputs[0])
group.links.new(Principled_Bsdf_node.outputs["BSDF"], output_node.inputs[0])

# Putting Node Group to the node editor
tree = bpy.context.object.active_material.node_tree
group_node = tree.nodes.new("ShaderNodeGroup")
group_node.node_tree = group
group_node.location = (-40,0)

#connections bewteen node group to output 

ShaderNodeOutputMaterial_node = tree.nodes["Material Output"]
links = tree.links    
link = links.new(group_node.outputs[0], ShaderNodeOutputMaterial_node.inputs[1])