Skip to content

Commit

Permalink
Update python example to use execute_query
Browse files Browse the repository at this point in the history
Using the new simpler API introduced in drivers 5.5 and stabilized in 5.8
  • Loading branch information
robsdedude authored and fbiville committed May 4, 2023
1 parent 2c25de7 commit b4dc295
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions code/python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@

from neo4j import GraphDatabase, basic_auth

driver = GraphDatabase.driver(
"neo4j+s://demo.neo4jlabs.com:7687",
auth=basic_auth("mUser", "s3cr3t"))

cypher_query = '''
MATCH (m:Movie {title:$movieTitle})<-[:ACTED_IN]-(a:Person) RETURN a.name as actorName
'''

with driver.session(database="movies") as session:
results = session.read_transaction(
lambda tx: tx.run(cypher_query,
movieTitle="The Matrix").data())
for record in results:
print(record['actorName'])

driver.close()
with GraphDatabase.driver(
"neo4j+s://demo.neo4jlabs.com:7687",
auth=("mUser", "s3cr3t")
) as driver:
result = driver.execute_query(
cypher_query,
movieTitle="The Matrix",
database_="movies")
for record in result.records:
print(record['actorName'])

0 comments on commit b4dc295

Please sign in to comment.