I had a graph living outside Pythonland (a commit tree with dependencies) and wanted to do graphy things to it. To do that, I first had to put the data into a NetworkX graph.
I wrote this code bit to discover a graph-like structure and put into a NetworkX (or similar enough) object.
It's basically a BFS scan, that delegates the actual node-to-edge discovery to a callable:

The edge_extractor callable should accept a node, and return edge-like tuples (either (source, dest) or (source, dest, data_dict)).
I do not bother to validate that the source node in the edges is indeed the node we're currently scanning.
An example call could be something like this: