Search code examples
pythonneo4jrest-clientneo4j.py

How to traverse a neo4j graph using python neo4jrestclient


I'm trying to follow the code example here: https://neo4j-rest-client.readthedocs.org/en/latest/traversals.html

n1.traverse(types=[client.All.Knows])[:]

But I don't understand what kind of obect 'client' is supposed to be, it wasn't defined in the example. When I try and do the same with my graphdb (one of the relations is 'belongsTo'), I get a NameError: name 'client' is not defined error:

from neo4jrestclient.client import GraphDatabase
gdb = GraphDatabase("http://myserver.....")

n = gdb.node[10]
ret = n.traverse(types=[client.All.belongsTo])
print ret

Solution

  • You just need

    from neo4jrestclient.client import All
    

    And then use All.belongsTo.

    In the docs, I am importing client directly.

    from neo4jrestclient import client