Getting output socket name and using it for input socket name in compositor
To get the name of the socket a node's input is linked to:

#using the File output node from your example
link = node.inputs[0].links[0] #gets the link from the input
socket_name = link.from_socket.name #returns the name of the socket the link is from