4

I'm using latest community Neo4j (2.2.0-M03) for storing my graphs. I'm interested in accessing it from Python. According to the official Neo4j documentation, there are several alternatives.

From what I have understood by checking the docs, playing around a bit, and checking this post, py2neo is the only one supporting Neo4j 2 (and labels). However, if I'd like to write and run specific algorithms on Neo4j, I should use Gremlin, through Bulbs, that however does not seem to support Neo4j 2.

Now, I would like to use some custom algorithms not currently in Neo4j, like Spreading Activation. Is writing algorithms directly in Neo4j in Java and running them from Python using cypher commands through py2neo the only alternative? Am I missing something?

Cheers

PS. I wanted to post links to all the software I cited but unfortunately I need at least 10 reputation to post more than 2 links...

Community
  • 1
  • 1
redsk
  • 261
  • 6
  • 11
  • Can you describe what you mean by "write algorithms"? What sort? Yes in general py2neo is the way to go, but it's going to be hard to give you advice if you don't specify what you're trying to do. – FrobberOfBits Jan 30 '15 at 15:29
  • Thanks @FrobberOfBits , I edited the question. I'd like to use custom algorithms, for example Spreading Activation. – redsk Jan 30 '15 at 16:16
  • This would be it "Is writing algorithms directly in Neo4j in Java and running them from Python through http the only alternative?" – Michael Hunger Feb 01 '15 at 13:47
  • @MichaelHunger if your phrasing is the actual question, then the answer is easy -- "no". :) – FrobberOfBits Feb 02 '15 at 13:15
  • Maybe @redsk is suggesting a use like with networkx, package of python? – user305883 Nov 27 '15 at 16:59

1 Answers1

4

This is a very tough question, it seems you need design guidance not a quick neo4j question. Depending on how you're using spreading activation, it might be better not to modify the server, but I can't tell because your use case is probably involved. Keep in mind that you can always use neo4j as a graph store, and then put higher-level concepts like spreading activation in your application code, not in the server.

The question presumes I think you want to put it in the server. So what are the options? Broadly, you could write a server plugin and extend the RESTful API (which wouldn't help you with py2neo) On the other hand, I don't think defining your own custom cypher function is supported right now, so you can't necessarily modify the cypher language itself, then use py2neo bindings to exploit a fancy new cypher function. Advice given elsewhere suggests you might want to consider an unmanaged extension to implemented spreading activation. If you did this, once again, I don't see how py2neo would help you.

Short term, I think you should consider NOT modifying neo4j itself, but rather putting your spreading activation in python code that maybe uses py2neo. Long-term, if neo4j comes up with a way of doing cypher user-defined functions (UDFs) which I understand is on the development roadmap (maybe?) then that might be a better option, but I wouldn't recommend it without many more requirements and details.

Community
  • 1
  • 1
FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86
  • Thank you @FrobberOfBits. I was actually trying to figure out which alternative I can take into account for devising a good design for my application. Neo4j unmanaged extensions are a good suggestion indeed. – redsk Feb 03 '15 at 16:06
  • A possible alternative would be using the [Gremlin](https://github.com/tinkerpop/gremlin/wiki) graph language (probably through [tinkerpop3](http://www.tinkerpop.com/) (not ready for Neo4j 2.2 afaik). In this case, p2neo supports calling a Gremlin script through a [specific extension](http://py2neo.org/2.0/ext/gremlin.html). – redsk Feb 03 '15 at 16:16
  • Finally, as you suggested, Spreading Activation (or other graph algorithms) could be implemented directly in Python (though py2neo, probably). In this case, however, I would probably expect performance to degrade a bit as each step of the algorithm would imply passing data back and forth from Neo4j to the Python application. – redsk Feb 03 '15 at 16:18
  • I don't know your app so I can't say for sure, but in general I recommend against premature optimization. Doing things outside of the DB also insulates you from the DB's API changes. You'll be writing extra python in any case, since if you go the unmanaged extension route (putting your algorithm into the DB) you'll still have to interface with that new algorithm in some way, which means more python than py2neo gives you out of the box. – FrobberOfBits Feb 04 '15 at 01:08