Are there any real instructions for using py2neo?

py2neo

(A Bramson) #1

I am using py2neo v4 with Python 3.6 and it's really hard to just get basic things done because there is basically no real instructions or examples. The official documentation " The Py2neo v4 Handbook" at https://py2neo.org/v4/index.html" is basically worthless because it doesn't include any examples of using most of the code and there is no description of how anything works there.

As a concrete example, I've got a node using
thisNode = list(matcher.match('Label1'))[0]
And now I want to get the list of nodes connected to this node via a particular kind of relationship.
I think this Cypher query works:
`list(graph.run("MATCH (n1)<-[:PARTOF]-(n2) WHERE ID(n1) = $thisID RETURN n2", parameters={"thisID":thisPrefNode.identity}).data())
And the question is: How do I do that in py2neo without using Cypher?
Since the parent node is already stored in a variable in python, this should be an easy thing to do, but...

And the broader question is where can I go real/learn about how py2neo works? There is barely any assistance on Stack Exchange, most of which is obsolete anyway. Is py2neo basically just not supported? In that case, is there a better way to interface between Python and Neo4j?


(A Bramson) #2

For this specific question, I actually found a partial answer in the handbook:

for rel in graph.match((alice, ), r_type="FRIEND"): print(rel.end_node["name"])

but, for my case the direction is in the wrong direction. The syntax is totally opaque, and the only guidance on what to even try to get the desired results is from the minimalist documentation: Parameters: nodes – Sequence or Set of start and end nodes (None means any node); a Set implies a match in any direction

There are no real instructions to explain the syntax nor any other examples for other use cases (like mine).
By trial and error I was able to figure out that
for rel in graph.match((None,alice), r_type="FRIEND"): print(rel.start_node["name"])
actually gets me what I want in this case, but by just putting a few more examples in the documentation would clarify the syntax and help many (and especially new) users.