python连接neo4j

根据[1]安装好neo4j以后

sudo neo4j start

运行下面的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from py2neo import Graph,Node, Relationship
test_graph = Graph(
    "http://localhost:7474",
    username="appleyuchi",
    password="appleyuchi"
)
a = Node('Person', name='Alice')
b = Node('Person', name='Bob')
test_graph.create(a)
test_graph.create(b)
r = Relationship(a, 'KNOWS', b)
test_graph.create(r)
print(a, b, r)
a['age'] = 20
b['age'] = 21
r['time'] = '2017/08/31'
print(a, b, r)

然后打开:

http://localhost:7474

得到

Reference:

[1]neo4j安装和启动