Search code examples
neo4jpy2neo

Py2neo Api for Neo4j


I was playing around with Py2neoAPI for Neo4j , can somebody tell me how to pull the data from the graph by using pull() method. Can someone give me an example.

I did the following:

Node1=Node("Person",Name="Kartieya");
Graph().create(Node1);
Graph().pull(Node1);

I am recieving the status as 200 , i.e. its working but how i am going to get the Node1.Name?


Solution

  • push and pull are only necessary for changes on existing nodes. create statements are carried out immediately.

    from py2neo import Graph, Node
    graph = Graph()
    
    # note the trailing ',' for tuple unpacking
    # 'create' can create more than one element at once
    node1, = graph.create(Node("Person",Name="Kartieya"))
    

    To get the Name property of your node do:

    print node1.properties['Name']
    

    If you now change a property you have to use push:

    node1["new_prop"] = "some_value"
    node1.push()
    

    pull is only needed if properties of node1 change on the server and you want to synchronize your local node1 instance.