Search code examples
pythongraphneo4jjupyter-notebook

Dump a Neo4j graph in pickle format from AURADS via pGraph or iGraph


I am using Jupyter Notebook to run cypher queries via py2neo and pygds libraries. The instance is hosted on AURADS. I am not able to dump the graph from Neo4j to local computer in a pickle file to explore later.

import neo4jupyter
import pickle
from py2neo import Graph as pGraph
from igraph import Graph as iGraph
from pygds import GDS
from graphdatascience import GraphDataScience

with open('graph.pkl', 'wb') as f:
    pickle.dump(pGraph("<instance_credentials>", auth=("neo4j", "<instance_password>")), f)
print("Hello")

Here is the error I get with the above code:

enter image description here

I think I need to query the whole graph data first and then pickle it?? I found this answer, but it is not exactly what I am looking for:here


Solution

  • It seems the easiest thing to do is to separately export nodes and relationships.

    You can export nodes using the following query:

    MATCH (n) RETURN n
    

    and relationships

    MATCH (n)-[r]->(m)
    RETURN n,r,m
    

    Some variation of these two queries should be good. You can also take a look at APOC export functions: https://neo4j.com/labs/apoc/4.3/export/

    Perhaps you could use apoc export to CSV and then construct a df from that:

    CALL apoc.export.csv.all("graph.csv", {})