[Neo] Groovy and Neo4J

James Richards heiho1 at mac.com
Tue Dec 2 23:07:22 CET 2008


Tobias,

> This sounds like a very nice project. I've wanted to do such a project
> myself but I've been kept back by lack of time.
>
> I am a committer on the Jython project, and focus mainly on the  
> compiler.
> About a year and a half ago I started a project for giving Neo4j a  
> more
> Pythonic feel when used from Jython (and CPython), it is in the Neo4j
> repository as neo4j.py:
> https://svn.neo4j.org/components/neo4j.py/trunk/This could be a place
> for you to start on your Neo4j/Django project.

I've been using Jython since the JPython days.  It's one of the  
indispensable tools in my kit.  I actually had your Neo4jpy checked  
out and it's installed.  The database is working through my CPython  
build but it looks like my latest trunk update of jython broke  
something [err, everything actually :P].

> At the moment I an busy working on a project I call RemoteNeo, it's an
> implementation of the Neo4j API that allows you to connect multiple  
> clients
> to one server. But I hope to put some effort into neo4j.py soon as  
> well
> (blog post with road map coming Monday or Tuesday). One thing I  
> would like
> to incorporate is support libraries for using Neo4j with Django, so  
> please
> submit feedback on places where the current neo4j.py feels awkward and
> extensions needed to use Neo4j in Django. Also let me know if I can  
> be of
> assistance in any way.

I have mixed feelings about the "multiple client for embedded  
database" but I do feel it will lead to wider adoption.  Along the  
lines of Django integration, this is something that I actually took a  
prolonged look at, in the midst of other projects.  I was interested  
in making Neo4J a swappable database backend for the standard Django  
orm.  The advantage of this is that Django Model and Admin classes  
could integrate directly with Neo4J.  There are some relational  
assumptions in the Django orm layer that are, probably, unavoidable in  
the current thinking on the "standard" web application stack.  I  
started to hack the Neo4J python layer into the Django backends but  
have been working on a different project for the last couple of weeks  
so I haven't returned to the initial code that I wrote.

What are your thoughts on integrating below the visible orm level?  To  
me, it seems quite feasible but would perhaps need some sort of an  
agreed upon set of relationship types for representing class  
hierarchies:

1) A standard "IS A" relationship for subclassing/interface  
implementation [allowing for jython Python-As-Java-Is-Java-As-Python  
thinking]
2) A standard "HAS A" type applied upon class members, to distinguish  
class-centric data from more arbitrary graph data

The above may be obviated but it was the only concern I could see for  
bridging the orm concept to Neo4J outside of traversals.  If this  
above makes sense, I can return to the code I put on the shelf.

> * Use with-statement for transactions:
>     with neo.transaction: ...
>   * Exception in the with-suite will cause rollback

I ran the matrix.py example from my CPython shell and tested out the  
two code branches for sub-2.5 and supra-2.5.  With the "Python >= 2.5  
version" commented out, the code runs fine:

"""
68-246-246-88:examples hanuman$ svn up
At revision 17.
8-246-246-88:examples hanuman$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>>
68-246-246-88:examples hanuman$ python matrix.py
Thomas Andersson's friends:
At depth 1 => Trinity
At depth 1 => Morpheus
At depth 2 => Cypher
At depth 3 => Agent Smith
Hackers:
At depth 4 => The Architect
68-246-246-88:examples hanuman$
"""

If I comment out the <= 2.5 code and uncomment the >= 2.5 code, I see  
an error:

"""
matrix.py:27: Warning: 'with' will become a reserved keyword in Python  
2.6
   File "matrix.py", line 27
     with Transaction() as tr:
                    ^
SyntaxError: invalid syntax
68-246-246-88:examples hanuman$
"""

The only other change I made to the matrix.py file was to explicitly  
import the Transaction class:

from neo4j import EmbeddedNeo, neo4j, Transaction

> Traversals are not that pretty yet, but they are supported, I would  
> love
> input on how you'd like to define traversals in Python code.


I'll let you know once I've had time to put together a small  
application.

Regards,

James



More information about the User mailing list