I tried the following and got the results I think you want:
from py2neo import neo4j, node, rel
graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
alice, = graph.create(node(name="Alice")) # Comma unpacks length-1 tuple.
bob, = graph.create(node(name="Bob"))
carol, = graph.create(node(name="Carol Smith"))
dev, = graph.create(node(name="Dev"))
graph.create(rel(alice, "KNOWS", bob))
graph.create(rel(dev, "KNOWS", carol))
graph.create(rel(alice, "KNOWS", carol))
My graph now looks like this in the browser:
Alternatively, you can create the graph in one graph.create()
statement:
from py2neo import neo4j, node, rel
graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
graph.create(
node(name="Alice"), #0
node(name="Bob"), #1
node(name="Carol Smith"), #2
node(name="Dev"), #3
rel(0, "KNOWS", 1),
rel(3, "KNOWS", 2),
rel(0, "KNOWS", 2)
)
And the output is the same. Hope this helps.