I think the sort of thing done below should work.
import networkx as nx
g = nx.complete_graph(4)
nx.set_node_attributes(g, {1: {"hello": "world"}})
nx.set_edge_attributes(g, {(2, 3): {"foo": "bar"}})
print(str(g.nodes.data()), str(g.edges.data()))
This produces output which shows node and edge attribute data:
[(0, {}), (1, {'hello': 'world'}), (2, {}), (3, {})] [(0, 1, {}), (0, 2, {}), (0, 3, {}), (1, 2, {}), (1, 3, {}), (2, 3, {'foo': 'bar'})]
There may also be some other way explained in this documentation on reading/writing Networkx graphs.