python调用neo4j的存储过程APOC

1.安装好neo4j数据库

2.安装apoc

3.python调用apoc



from py2neo import Graph from neo4j import GraphDatabase class Neo4jSearch(): def __init__(self): self.driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "123456")) def call_proc(self): ''' neo4 4.1版本上调用apoc :return: ''' with self.driver.session() as session: # cypher = "CALL apoc.help('dijkstra')" # cypher = "CALL apoc.algo.community(25,null,'partition','X','OUTGOING','weight',10000)" # cypher = " return apoc.number.format(12345.67) as value" # cypher = '''return apoc.date.parseAsZonedDateTime('2012-12-23 23:59:59','yyyy-MM-dd HH:mm:ss', 'UTC')''' # cypher = '''return apoc.date.parse('2012-12-23','ms|s|m|h|d','yyyy-MM-dd')''' # cypher = "CALL dbms.procedures() YIELD name WHERE name CONTAINS 'shortest' RETURN *" cypher = "return apoc.date.parse('2012-12-23','d','yyyy-MM-dd')" data = session.run(cypher).data() print(data) session.close() self.driver.close() if __name__ == "__main__": Neo4jSearch().call_proc()

适用于neo4j 3.5版本及以上,通过python调用apoc.

注意:neo4j图数据与apoc版本一致。

原文地址:https://www.cnblogs.com/liangxinxinbo/p/13469623.html