Api Examples
py
# create neo4j conneciton usin python
from neo4j import GraphDatabase
# python singleton class
class Neo4jConnection:
def __init__(self, uri: str, user: str, password: str):
self.driver = GraphDatabase.driver(
uri=uri,
auth=(user, password),
)
self.session = self.driver.session()
def get_all_nodes_with_label(self, label):
result = self.session.run(f"MATCH (n:{label}) RETURN n")
nodes = []
for record in result:
nodes.append(record["n"])
return nodes
def get_nodes(self, type: str):
result = self.session.run(f"MATCH (n:{type}) RETURN n")
nodes = []
for record in result:
nodes.append(record["n"])
return nodes
def get_relationships(self, type: str):
result = self.session.run(f"MATCH (n:{type})-[r]->(m) RETURN n,r,m")
relationships = []
for record in result:
relationships.append(record["r"])
return relationships
def close(self):
self.session.close()
self.driver.close()
if __name__ == "__main__":
neo4j_connection = Neo4jConnection(
uri="neo4j+ssc://<NEO4j_URI>",
user="neo4j",
password="<PASSWORD>"
)
print("=== get project nodes ===")
nodes = neo4j_connection.get_nodes("Project")
print(nodes)
print("=== get context nodes ===")
nodes = neo4j_connection.get_nodes("Context")
print(nodes)
print("=== get shot nodes ===")
nodes = neo4j_connection.get_nodes("Shot")
print(nodes)
print("=== get task nodes ===")
nodes = neo4j_connection.get_nodes("Task")
print(nodes)
print("=== get settings nodes ===")
nodes = neo4j_connection.get_nodes("Settings")
print(nodes)
print("=== get template path nodes ===")
nodes = neo4j_connection.get_nodes("TemplatePath")
print(nodes)
print("=== get relationships ===")
relationships = neo4j_connection.get_relationships("Task")
print(relationships)
relationships = neo4j_connection.get_relationships("Shot")
print(relationships)
relationships = neo4j_connection.get_relationships("Context")
print(relationships)
relationships = neo4j_connection.get_relationships("Project")
print(relationships)
neo4j_connection.close()