Can I change the "Socket_#" datapath name for Geometry Nodes to something descriptive?

I’m writing a python script which need to read and write some properties on a geometry nodes I’ve created. Unfortunately, the names of the sockets in the datapaths I need to use are all “Socket_#”. It would be nice if I could use a more descriptive name, since it will be hard to keep track of what “Socket_4” is vs “Socket_14”.

That is, if I copy the datapath from “Radius Base” in the properties panel, I get:

modifiers["GeometryNodes"]["Socket_2"]

“Socket_#” identifier is assigned once when you create the socket and never changes even if you rename the socket.

the name is just a display label. it can be anything and can be non-unique. nothing stops you from naming two sockets “Radius”, which is why Blender does not use names as keys.

use something like this:

def find_socket_id(modifier, name):
    for item in modifier.node_group.interface.items_tree:
        if item.item_type == 'SOCKET' and item.in_out == 'INPUT' and item.name == name:
            return item.identifier
    raise KeyError(f"no input socket named {name!r}")

but keep in mind names are not unique! if two sockets share a name, find_socket_id returns whichever comes first in the list. if you are building a modifier library which Python code uses, use identifiers. if you just scripting for your nedes, you can use the func above.

but you can also use it if you are careful enough to not use duplicate names in your modifiers. but still, your code will need to loop the items tree every time to find sockets by their names.

also just in case, i think it is somewhere 4.0+ API. you did not mention which version you are using.