# How to set the socket type in python?

How can I set the output socket type of a nodegroup output socket from python?

I don't even know of any good way to do this in the UI.. The only way I know of in the UI is to connect a node output of the type I want (e.g. a yellow color output) to the Group Output node.

I tried setting socket.type, however there is no error message and the socket type does not change.

This is important because the default is a 'VALUE' socket, which converts colors into grayscale.

Here is the relevant part of my script:

main_group = bpy.data.node_groups.new(type="ShaderNodeTree", name="Object Color")
main_group.outputs.new("NodeSocketFloat", "Object Color")
output_node = main_group.nodes.new("NodeGroupOutput")
output_node.location = (600, 0)
output_node.inputs["Object Color"].type = 'RGBA'


You define the type when you create the socket with new() Looking at the list on the bpy.types page there are several starting with NodeSocket that can be used.

The variations of each type alter the visual display - eg. FloatPercent shows % with the value.

NodeSocketBool
NodeSocketColor
NodeSocketFloat
NodeSocketFloatAngle
NodeSocketFloatFactor
NodeSocketFloatPercentage
NodeSocketFloatTime
NodeSocketFloatUnsigned
NodeSocketInt
NodeSocketIntFactor
NodeSocketIntPercentage
NodeSocketIntUnsigned
NodeSocketString
NodeSocketVector
NodeSocketVectorAcceleration
NodeSocketVectorDirection
NodeSocketVectorEuler
NodeSocketVectorTranslation
NodeSocketVectorVelocity
NodeSocketVectorXYZ


To update sambler's answer, here's the updated list of node socket types.

Here I did a little script that creates a node group with all sockets available (2.92)

import bpy

#toggle comment the previous line and uncomment the next line to create a Geometry Node Group
#allSockets = bpy.data.node_groups.new("All Sockets Geometry", "GeometryNodeTree")

for nm in ["Bool",
"Collection",
"Color",
"Float",
"FloatAngle",
"FloatFactor",
"FloatPercentage",
"FloatTime",
"FloatUnsigned",
"Geometry",
"Image",
"Int",
"IntFactor",
"IntPercentage",
"IntUnsigned",
"Object",
"String",
"Vector",
"VectorAcceleration",
"VectorDirection",
"VectorEuler",
"VectorTranslation",
"VectorVelocity",
"VectorXYZ",
"Virtual"]:
type = "NodeSocket" + nm
print(nm +" is a node socket of type "+ type)

allSockets.inputs.new(type, nm)
allSockets.outputs.new(type, nm)