RedisGraph Python Client
Project description
redisgraph-py
RedisGraph python client
Example: Using the Python Client
import redis
from redisgraph import Node, Edge, Graph, Path
r = redis.Redis(host='localhost', port=6379)
redis_graph = Graph('social', r)
john = Node(label='person', properties={'name': 'John Doe', 'age': 33, 'gender': 'male', 'status': 'single'})
redis_graph.add_node(john)
japan = Node(label='country', properties={'name': 'Japan'})
redis_graph.add_node(japan)
edge = Edge(john, 'visited', japan, properties={'purpose': 'pleasure'})
redis_graph.add_edge(edge)
redis_graph.commit()
query = """MATCH (p:person)-[v:visited {purpose:"pleasure"}]->(c:country)
RETURN p.name, p.age, v.purpose, c.name"""
result = redis_graph.query(query)
# Print resultset
result.pretty_print()
# Use parameters
params = {'purpose':"pleasure"}
query = """MATCH (p:person)-[v:visited {purpose:$purpose}]->(c:country)
RETURN p.name, p.age, v.purpose, c.name"""
result = redis_graph.query(query, params)
# Print resultset
result.pretty_print()
# Use query timeout to raise an exception if the query takes over 10 milliseconds
result = redis_graph.query(query, params, timeout=10)
# Iterate through resultset
for record in result.result_set:
person_name = record[0]
person_age = record[1]
visit_purpose = record[2]
country_name = record[3]
query = """MATCH p = (:person)-[:visited {purpose:"pleasure"}]->(:country) RETURN p"""
result = redis_graph.query(query)
# Iterate through resultset
for record in result.result_set:
path = record[0]
print(path)
# All done, remove graph.
redis_graph.delete()
Installing
Install official release
pip install redisgraph
Install latest release (Aligned with RedisGraph master)
pip install git+https://github.com/RedisGraph/redisgraph-py.git@master
Install for development in env
-
Create a virtualenv to manage your python dependencies, and ensure it's active.
virtualenv -v venv; source venv/bin/activate
-
Install pypoetry to manage your dependencies.
pip install poetry
-
Install dependencies.
poetry install
tox runs all code linters as its default target.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
redisgraph-2.4.3.tar.gz
(13.4 kB
view hashes)
Built Distribution
redisgraph-2.4.3-py3-none-any.whl
(14.3 kB
view hashes)
Close
Hashes for redisgraph-2.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac90b3c2bfab35213b66fc80e259a22782b5619efcc17035c9bb626c3dd9f54a |
|
MD5 | b0fc8a5d9c4c56a145f3d23b9b4d574f |
|
BLAKE2b-256 | 8efd7124415e216211df711972f5443dc4ddad053fa34f3a6cdd412ad57bc8f0 |