Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve a node's properties in Python with Neo4j, you can use the data() method on the node object. Here's an example code snippet:

from neo4j import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
session = driver.session()

result = session.run("MATCH (n:Person) WHERE n.name = 'John' RETURN n")
node = result.single()["n"]
properties = node.data()

print(properties)

In this example, we first create a connection to the Neo4j database using the GraphDatabase class. Then we open a session using the driver.session() method. We execute a Cypher query to retrieve a node with the name "John", and then we use the result.single() method to retrieve the single record that was returned. We access the node object using the key "n", and then use the data() method to retrieve the node's properties. Finally, we print the properties to the console.