NeoNx - NetworkX to Neo4j


I was playing around with NetworkX, an excellent graph library for python. I wanted to upload the data I created to Neo4j. But I couldn’t find an easy way of doing this. So I created a library to move a NetworkX graph to Neo4j through two methods:

  • Convert a networkx graph to Geoff compatible string which could then be uploaded through a varity of ways.

  • Directly upload the graph using the Neo4j Batch REST API

To install:

pip install neonx

To upload a graph to neo4j

import networkx as nx

import neonx

graph = nx.balanced_tree(2, 1, create_using=nx.DiGraph())
result = neonx.write_to_neo("http://localhost:7474/db/data/", graph, "LINKS_TO")

I am assuming that all the properties of the nodes and edges are json encodeable. If not, you can easily pass a json encoder object to handle custom data types as mentioned here. Example here.

Comments/contributions welcome here!