from redisgraph import Graph # create a new graph graph = Graph('mygraph', host='localhost', port=6379) # add nodes graph.query("CREATE (:Person {name:'Alice', age:30})") graph.query("CREATE (:Person {name:'Bob', age:40})") # add edges graph.query("MATCH (a:Person {name:'Alice'}), (b:Person {name:'Bob'}) CREATE (a)-[:FRIEND]->(b)")
# get all nodes and their properties result = graph.query("MATCH (n) RETURN n") # get all Person nodes and their names result = graph.query("MATCH (p:Person) RETURN p.name") # get all friends of Alice result = graph.query("MATCH (a:Person {name:'Alice'})-[:FRIEND]->(b:Person) RETURN b.name")These examples show how to run queries against the graph to retrieve data from it. In terms of package library, RedisGraph is a Python library that can be installed via pip.