Book Image

Building web applications with Python and Neo4j

By : Sumit Gupta
Book Image

Building web applications with Python and Neo4j

By: Sumit Gupta

Overview of this book

Table of Contents (14 chapters)
Building Web Applications with Python and Neo4j
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a social network with py2neo


In the previous section, we saw the important APIs exposed by py2neo along with examples for each of them. In this section, we will further use these APIs and see their practical implementations in real-world scenarios.

Let's recreate the social network data which we created using Cypher in Chapter 2, Querying the Graph with Cypher, using various APIs and methods exposed by py2neo.

First and foremost, we will clean up our database, so perform the following steps to do that:

  1. Open your console or command prompt and execute <$NEO4J_HOME>\bin\neo4jshell.

  2. Execute the following Cypher queries to delete the data from Neo4j database:

    OPTIONAL MATCH (n)-[r]-(n1) delete r,n.n1;
    MATCH n delete n;

Next we need to write some Python and code using py2neo to create a graph, which will look something like the following figure:

The previous illustration shows the layout of the data model which we will be creating using py2neo APIs.

Perform the following steps to create...