Search code examples
python-2.7neo4jpy2neo

How to return node from py2neo graph query?


How can i use the result and convert it to node or relationship from graph.run for eg.

result = graph.run('match (x:Person) return x')

How can i convert result to Py2neo v3 node/relationship?


Solution

  • The simplest way to obtain the node from your query is to use evaluate instead of run:

    my_node = graph.evaluate('match (x:Person) return x')
    

    This method returns the first value from the first record returned. In this case, your node.

    http://py2neo.org/v3/database.html#py2neo.database.Graph.evaluate