# Is it possible to find the nodes connected to a node in python?

Is it possible to find nodes connected to a node?

For example, could you trace your way back through a node tree from the material output node by finding the node connected to the material output node, then finding the node(s) connected to that node, then the nodes connected to those nodes, etc.?

How is this possible?

The python path to the links between each node is

bpy.data.materials[].node_tree.nodes[].inputs[].links[].from_node


So for each material we want to start at the Material Output node then loop through each array of inputs[] and links[] to move through the connections. Going this way (using from_node) there should only be one link for each input, but if you want to reverse the order (by using to_node) you can have multiple links for each output.

import bpy

for n_inputs in node_in.inputs: