cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to get cypher query result in python

considered I run below query in neo4j browser. It will shows some nodes in neo4j display panel and how many nodes and relationships in this query have.

I wish to get the "nodes count and relationship" count when i execute the query in python way.

query:
match(n) return(n) limit 5

results of query in the browser shows : "Displaying 5 nodes, 1 relationships"

I am using python3.5 and module as "from neo4j import GraphDatabase"

2 REPLIES 2

When you execute the Cypher query with the python driver, call the consume() method on the result object like so:

https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.Result.consume

Then I believe you can use the "counters" member of that object that comes back; see SummaryCounters in the API here

https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.ResultSummary

Thanks david.allen,

i tried the below code. But i got '{}'.

from neo4j import GraphDatabase
driver = GraphDatabase.driver("bolt://0.0.0.0:7687", auth=("neo4j", "xxxx"))
session = driver.session()
q1="MATCH(n) return n limit 5"
nodes = session.run(q1)
print(nodes.consume().counters)