https://github.com/RedisGraph/redisgraph-py
RedisGraph python client
https://github.com/RedisGraph/redisgraph-py
cypher graphdatabase python-client redis redisgraph-python-client
Last synced: 9 months ago
JSON representation
RedisGraph python client
- Host: GitHub
- URL: https://github.com/RedisGraph/redisgraph-py
- Owner: RedisGraph
- License: bsd-3-clause
- Created: 2017-09-22T12:54:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-08T08:29:55.000Z (almost 3 years ago)
- Last Synced: 2025-03-11T02:24:21.897Z (10 months ago)
- Topics: cypher, graphdatabase, python-client, redis, redisgraph-python-client
- Language: Python
- Homepage: https://redisgraph.io
- Size: 141 KB
- Stars: 188
- Watchers: 7
- Forks: 49
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/RedisGraph/redisgraph-py)
[](https://badge.fury.io/py/redisgraph)
[](https://github.com/RedisGraph/redisgraph-py/releases/latest)
[](https://codecov.io/gh/RedisGraph/redisgraph-py)
[](https://snyk.io/test/github/RedisGraph/redisgraph-py?targetFile=pyproject.toml)
[](https://lgtm.com/projects/g/RedisGraph/redisgraph-py/alerts/)
# RedisGraph python client
[](https://forum.redis.com/c/modules/redisgraph)
[](https://discord.gg/gWBRT6P)
## Deprecation notice
As of [redis-py 4.1.0](https://pypi.org/project/redis/4.1.0) this library is deprecated. It's features have been merged into redis-py. Please either install it [from pypy](https://pypi.org/project/redis) or [the repo](https://github.com/redis/redis-py).
--------------------------------
## Example: Using the Python Client
```python
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
1. Create a virtualenv to manage your python dependencies, and ensure it's active.
```virtualenv -v venv; source venv/bin/activate```
2. Install [pypoetry](https://python-poetry.org/) to manage your dependencies.
```pip install poetry```
3. Install dependencies.
```poetry install```
[tox](https://tox.readthedocs.io/en/latest/) runs all code linters as its default target.