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?

0 Likes

(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.

1 Like

(A Bramson) #3

So I guess the answer is "No. There is no real support or documentation for py2neo. And there is no better way for Python to interact with Neo4j. You're on your own and it's totally hopeless." That's pretty sad if you are looking for customers for your technology.

0 Likes

(Andrew Bowman) #4

Looks like your post fell through the cracks, sorry about that. Let's get that fixed up.

You may want to try using the Python bolt driver as the means to interface with Neo4j via Cypher

Or if you want to stick with Py2Neo, here's a blog post with some examples of usage:

0 Likes

(A Bramson) #5

Thank you for responding, but if those are the two best sources you can point me to, then it seems the answer hasn't changed. There is basically no real explanation or useful examples for the vast majority of the commands listed in the documentation, and no resources for getting help learning to use Neo4j or its Python drivers.

I'm working on a pilot project using graph databases in my company, but after my experiences struggling for hours to perform basic functions, I really can't recommend this technology. Not because of what it can and cannot do, but because there is no way to train our engineers to do what they need to do.

I highly recommend committing serious time/effort in some actual instruction and more complete documentation (basically just add a lot more examples covering a lot more use cases to the documentation). You might also considering having people respond to posts on Stack Exchange and/or your own forum.

0 Likes

(Andrew Bowman) #6

Regarding the Python bolt driver, the page I linked to should have additional links at the bottom to our drivers documentation which should be applicable for all drivers (including Python)

https://neo4j.com/docs/developer-manual/current/drivers/

I just wanted to make sure you've visited that part of the documentation, as it does contain examples of usage.

When using the bolt drivers, most of your Python code around driver usage won't change much, it will just be the Cypher executed (and perhaps parameters passed) and how you consume the results that will change.

0 Likes

(Andrew Bowman) #7

One additional thing to keep in mind...

Py2Neo isn't officially company supported. It's a community driver, volunteer-based project, and while there are some engineers who contribute to it, it's not something Neo4j the company has adopted for full support/documentation/love+care. We'll do best-effort, and get those involved who contribute to the project, but it is not a Neo4j product.

The Python bolt drivers, however, are under the company's stewardship, so we have official documentation and examples present, which I've linked to.

0 Likes

(Andrew Bowman) #8

As for using Neo4j itself, we do have plenty of resources, starting with our developers manual, but we certainly are not lacking here.

Here's a few links to start with:

https://neo4j.com/docs/developer-manual/3.4/

If you have questions about certain aspects or topics in our documentation, we're more than happy to point you in the right direction.

2 Likes

(Icfly2) #9

While it is cheap to bash documention, I'm afraid I agree with the original question, the docs / examples for learning CYPHER are pretty dire and the support for python is meak.
The examples in the guide are either very basic or partial.

As for what to do: Try around in Cypher in the app, ask stackoverflow and the docs and then work your way through it. Then run the code from python or wherever. Not ideal but so far the only way I can make it work.

I'm very impressed with some of Neo4js capabilities and underwhelmed with others, but I guess that is normal for new tech your learning. I have yet to visit a training session and hope that it will help me along.

Best,

Ruben

0 Likes

(Michael Hunger) #10

Hi Ruben,

I would love if you could point out specific things that you feel are too weak.
Also which topics you want to know more about.

Did you see the new online intro course which tries to remedy some of the Cypher learning issues:

0 Likes

(Icfly2) #11

I'm not in a position to say how the docs should look, as I haven't learned enough about cypher however an example of a particularly irritating page would be: optional match where the examples given are trivial and return null, hardly something useful to learn from. In general most example pages have only very basic queries and to get to understand how to construct more complex ones is more difficult than necessary.

Just as a guide, the answers on SO rarely link to relevant pages in the docs, while in other languages and packages where the docs are more complete they do so for basic questions like the cases just described.

And no I haven't tried the course and if it addresses the above issues that is great, but really that should go into the manual as a lookup not hidden in a course.

0 Likes

(Michael Hunger) #12

Thanks a lot for your feedback, we will improve the docs overall.

Are you in general looking more for intro to new topics or solutions to really tricky questions?

For the latter the knowledge base is a much better fit (neo4j.com/developer/kb) which is more "how-to" oriented. The docs are more reference docs in that regard.

Did you see this intro which is more of a tutorial: https://neo4j.com/docs/getting-started/current/cypher-intro/

0 Likes

(Andrew Bowman) #13

That's interesting, the examples for OPTIONAL MATCH were chosen specifically because they result in no matches and so return null for the newly introduced variables. This is what differentiates an OPTIONAL MATCH from a MATCH...when the pattern is present then it behaves identically, but when it's not present it behaves differently, since MATCH would wipe out the row entirely, and OPTIONAL MATCH instead keeps the row and sets newly introduced variables to null.

In short, you would use OPTIONAL MATCH when there may be certain connected nodes that you want to use or output, but you don't want to disqualify your match so far (don't want to wipe it out) if such a pattern doesn't exist. The thinking when using this is: I want to get this if it exists, but it's fine if it doesn't.

In light of this, does that help you understand what OPTIONAL MATCH is for, and does that suggest any more specific points that would have made the purpose and usage clearer?

0 Likes

(Tkk2012) #14

Same problem here!
And I eventually find answers from this post, not from that 'handbook':dizzy_face:

0 Likes