Book Image

Neo4j Cookbook

By : Ankur goel, Ankur Goel
Book Image

Neo4j Cookbook

By: Ankur goel, Ankur Goel

Overview of this book

Table of Contents (17 chapters)
Neo4j Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Annotate the Python object model to the Neo4j graph database


In this recipe, we will learn how to map the Python object model to the Neo4j graph database server.

Getting ready

Neomodel is an excellent binding module used for mapping an object model to the Neo4j graph database, thinking in terms of objects and further enhancing properties, relationships, and so on.

Neomodel can be installed from both via pip and easy_install:

$ pip install neomodel
$ easy_install neomodel

Now, set the location of Neo4j via the environment variable:

export NEO4J_REST_URL="http://<ip:port>/db/data"

How to do it...

Let's create our first relationship model using Neomodel, as shown in the following code:

from neomodel import (StructuredNode, StringProperty, IntegerProperty,RelationshipTo, RelationshipFrom)
class Movie(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    actors = RelationshipFrom('Actor', 'ACTED_IN')
class Actor(StructuredNode):
    name = StringProperty(unique_index...