Once the connection is created, we need to create a session object from this connection. This can be achieved in a simple way:
session = driver.session()
All the created sessions need to be closed after we are done with them. This can be done by calling session.close() after our code, but we are going to use a more Pythonic method using the context manager and the with statement:
with driver.session() as session:
# code using the session object goes here
pass
Using this syntax, the session will be automatically closed when exiting the with block, and trying to use the session object out of this block will raise an exception.
Let's now actually use the session to send some Cypher queries to the graph and get the result back. The simplest way to do this is to use auto-commit transactions:
result = session.run("MATCH (n:Node) RETURN n")
To get a record from the result, several methods are possible. In order to take a look at an example, we can use the .peek...