Last active
March 8, 2022 06:28
-
-
Save abroniewski/eeb60eed5d53a18a6b8f6377e8980a2a to your computer and use it in GitHub Desktop.
An example of how to connect to neo4j from Python and create a couple nodes in Cypher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from neo4j import GraphDatabase | |
uri = "neo4j://localhost:7687" | |
driver = GraphDatabase.driver(uri, auth=("neo4j", "password")) | |
def create_friend_of(tx, parameter_name, parameter_friend): | |
tx.run("MATCH (a:Person) WHERE a.name = $name " | |
"CREATE (a)-[:KNOWS]->(:Person {name: $friend})", | |
name=parameter_name, friend=parameter_friend) | |
with driver.session() as session: | |
session.write_transaction(create_friend_of, "Alice", "Bob") | |
with driver.session() as session: | |
session.write_transaction(create_friend_of, "Alice", "Carl") | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment