Accessing Neo4j from Python using the REST bindings
The REST interface is widely used and in this recipe, we will learn how to access Neo4j from Python using the REST Bindings.
Getting ready
The py2neo module (http://py2neo.org/2.0/) is an excellent Python binding module used to connect to the Neo4j REST API server.
The py2neo module can be installed from both pip
and easy_install
, as shown here:
$ pip install py2neo $ easy_install py2neo
How to do it...
The following steps will get you started with this recipe:
First, we will create our first node assuming the default installation, as shown in the following code:
from py2neo import neo4j graph = neo4j.GraphDatabaseService(ENDPOINT_URL) graph.create(node(name="A")
Next, let's create our first relation using the py2neo module:
from py2neo import neo4j graph = neo4j.Graph(ENDPOINT_URL) graph.create(node(name="A"), node(name="B")) rel(1, "PLAYS WITH", 2) rel(2, "FATHER OF", 1)