Python networkx : edge contraction
How about:
add_node(XYZ)
add_edge(XYZ, A)
for edge incident on (X, Y, Z):
v = nodes in edge not in (X, Y, Z, A)
if v:
remove_edge(edge)
add_edge(v, XYZ)
for node in (X, Y, Z):
remove_node(node)