[Neo] Groovy and Neo4J

Tobias Ivarsson tobias.ivarsson at neotechnology.com
Wed Dec 3 11:08:52 CET 2008


On Tue, Dec 2, 2008 at 11:07 PM, James Richards <heiho1 at mac.com> wrote:

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


I'll take a look at that right away.

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


One thing I am hoping to achieve with this is to connect to Neo4j from
Non-jvm-systems, such as .NET, I'm working concurrently on a client to
enable this.


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


I've had a look at creating a Django database backend using Neo4j as well,
but the relational assumptions were pretty discouraging. One thought I had
was to implement a version of the model package (the ORM) that uses Neo4j.
This would mean that you had to use a different (but very similar) system to
define the model, but could then use the same application logic. The big
downside of this is of course that it would not work with the Django Admin
system, and the Admin system is one of the most appealing features of
Django.

If you think it's possible to create a database backend without having to
parse SQL that could be an exellent approach.
And if you would be willing to share the code you have started in that
direction it would be even better. ;)

After my last e-mail I got an idea that I should have gotten earlier: since
I'm doing a presentation on Jython and Django on Jython on Devoxx next week
it would be cool to integrate Neo4j in that demo. So I would like to get
something (that might not be perfect, but that works) up and running by
then.


>
> 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 "IS A" relation might be a good idea, but I have some doubts on "HAS A",
since it would require linear scanning for members. But for the
read-modify-write approach of an ORM this whould be acceptable.

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


Since the version in the repository has not been updated since b3 of Neo4j
and since Neo4j has received IoC refactorings since then the Transaction
class is going away and will be replaced with a transaction property on the
neo instance instead.

>
>
> > 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
>
> _______________________________________________
> Neo mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Tobias Ivarsson <tobias.ivarsson at neotechnology.com>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857


More information about the User mailing list