How to import a networkX graph to neo4j?

I have a graph created with networkX and I am using neonx to import it to neo4j on localhost. I have a networkX type graph called G. Below is the code:

data1 = json_graph.node_link_data(G) H = json_graph.node_link_graph(data1) results = neonx.write_to_neo("", H, 'LINKS_TO') 

The error I get is:

Traceback (most recent call last): File "/Users/aman/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-5-0d401e8987b7>", line 31, in <module> results = neonx.write_to_neo("", H, 'LINKS_TO') File "/Users/aman/venv/lib/python3.7/site-packages/neonx/neo.py", line 86, in write_to_neo batch_url = all_server_urls['batch'] KeyError: 'batch' 

2 Answers

I believe the issue is that your neo4j instance requires authentication, but neonx doesn't appear to support it.

to disable authentication set: dbms.security.auth_enabled=false (see: )

to verify this is the issue point your browser to: and see if you are prompted for a user and password

Best way is to dump networkx graph and import it into Neo4j.

Advantages:

  • You don't need to have a working connection with Neo4j server
  • Dump once and load it anywhere anytime. You have saved version/backup.

Dump networkx graph:

nx.write_graphml(g, 'path/to/file.graphml') 

Load into Neo4j:

  • Install apoc plugin for Neo4j from here
  • Enable apoc.import.file.enabled=true in conf/neo4j.conf
  • Place your graph dump file.graphml in import/ folder
cypher-shell -a bolt://localhost:7687 "call apoc.import.graphml('file.graphml', {})" 

Or in browser:

call apoc.import.graphml('file.graphml', {}) 

For more details:

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like