1. 程式人生 > 實用技巧 >python呼叫neo4j的儲存過程APOC

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版本一致。