跳转到主要内容

RedisGraph Python客户端

项目描述

license CircleCI PyPI version GitHub issues Codecov Known Vulnerabilities Total alerts

redisgraph-py

Forum Discord

RedisGraph python客户端

示例:使用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()

安装

安装官方版本

pip install redisgraph

安装最新版本(与RedisGraph master同步)

pip install git+https://github.com/RedisGraph/redisgraph-py.git@master

在env中安装开发版本

  1. 创建一个虚拟环境来管理您的python依赖项,并确保它是激活的。virtualenv -v venv; source venv/bin/activate

  2. 安装pypoetry来管理您的依赖项。pip install poetry

  3. 安装依赖项。poetry install

tox默认运行所有代码检查器。

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定选择哪个,请了解更多关于安装包的信息

源分布

redisgraph-2.4.4.tar.gz (13.5 kB 查看哈希值)

上传时间

构建分布

redisgraph-2.4.4-py3-none-any.whl (14.3 kB 查看哈希值)

上传时间 Python 3

支持