Python编程:py2neo操作neo4j图数据库

网友投稿 772 2022-05-30

py2neo文档: https://py2neo.org/v4/index.html

安装:

pip install py2neo

1

本文用的版本是:

py2neo 4.1.3

代码示例

# -*- coding: utf-8 -*- from py2neo import Graph, Node, Relationship, NodeMatcher from py2neo.matching import RelationshipMatcher # 连接数据库 graph = Graph("http://localhost:7474", username="neo4j", password='123456') # 创建节点 p1 = Node("Person", name="张三") p2 = Node("Person", name="李四") graph.create(p1) graph.create(p2) # 创建关系 r = Relationship(p1, "认识", p2) graph.create(r) # 节点查询 mather = NodeMatcher(graph) result = mather.match("Person", name="张三").first() print(result) # (_0:Person {name: '\u5f20\u4e09'}) # 查询关系 relation_matcher = RelationshipMatcher(graph) ret = relation_matcher.match((result,), r_type="认识").first() print(ret) # (张三)-[:认识 {}]->(李四) # 直接运行cypher语句 ret = graph.run('match(p:Person{name:"李四"}) return p').data() print(ret) # [{'p': (_3:Person {name: '\u674e\u56db'})}]

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

Python编程:py2neo操作neo4j图数据库

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

Python 数据库

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:八十、 Springboot整合异步任务和定时任务
下一篇:Node.js:解析浏览器ua-UserAgent
相关文章