import networkx as nx # Create an instance of a graph G = nx.Graph() # Create an edge between two nodes. The nodes will be also created. G.add_edge('A', 'B', weight=6)