[Home] [Articles, Categories, Tags] [Books, Quotes]
Building Web Applications with Python and Neo4j
Author:
Pub Year:
Source:
Read: 2016-11-26
Last Update: 2016-11-26

Five Sentence Abstract:

The first half focuses on setting up the software and interacting with your first graph database using cypher. The second half is overloaded with basic Flask and Django based tutorials alongside deployment issues like caching, fault tolerance, clustering, and other advanced features. It provides a nice overview, but a whole book could be written about each of the last three chapters.

Thoughts:

Although old, this book provided an overview of both the cypher and neo4j's technical side.

A whole book could be written demonstrating uses of neo4j in Flask or Django. The overviews there seemed too condensed. I would have rather had more details for the topics in chapter 7, on deployment/production options.

Exceptional Excerpts:

Notes:

// designates my notes.

@@@ designates important.

// Uses neo4j 2.2

Chapter 1 - Your First Query with Neo4j

page 14:

Chapter 2 - Querying the Graph with Cypher

page 24:
page 25:
1
2
MATCH (x:MALE) WHERE x.age is NOT NULL and x.name is NOT NULL RETURN
count(DISTINCT x.name);
page 32:
1
MATCH (n:MALE {name: "Andrew", age:24}) remove n.age return n;
page 36:
1
2
3
MATCH (n)
where n.name IN["John","Andrew"] and n.age is Not Null
return n;
1
2
3
MATCH (n)
where n.name =~"J.*"
return n;
page 37:
1
MATCH (n)return n ORDER by n.name, n.age SKIP 3 LIMIT 2;
page 38:
1
2
3
4
MATCH (x{ name: "Bradley" })--(y)-->()
WITH y, count(*) AS cnt
WHERE cnt> 1
RETURN y;
1
2
3
MATCH (x:MALE)-[:FRIEND]->() return x.name, labels(x)
UNION
MATCH (x:FEMALE)-[:FRIEND]->()return x.name, labels(x);
page 41:
1
2
MATCH (x{name:"Bradley"})-[:FRIEND]->(friend)<-[:FRIEND]-(otherFriend)
return distinct friend.name as CommonFriend;
1
2
3
Match (me{name:"Bradley"})-[r:FRIEND]-(myFriend),(myFriend)-[:FRIEND]-(otherFriend)
where NOT (me)-[:FRIEND]-(otherFriend)
return otherFriend.name as NotMyFriends;
page 42:
1
2
3
MATCH (movie:MOVIE)<-[r:HAS_RATED*0..]-(person)
return movie.name as Movie, count(person)-1 as
countOfRatings order by countOfRatings;
page 43:
1
2
MATCH (x{name:"Bradley"})-[:FRIEND]->(friend)-[r:HAS_RATED]->(movie)
return friend.name as Person, r.ratings as Ratings,movie.name as Movie;

Chapter 3 - Mutating Graph with Cypher

page 47:
page 49:
page 50:

page 51:
page 52:
page 53:

page 55:
page 56:
page 58:
1
2
3
MATCH (f:FEMALE {name: "Sheena"})
SET f:NONVEG
return f;
1
2
3
4
MATCH (f:FEMALE {name: "Sheena"})
REMOVE f:NONVEG
SET f:VEG
return f;
page 59:
1
CREATE INDEX ON :MALE(name);
page 60:
1
DROP INDEX ON :MALE(name);
1
2
3
4
MATCH (n:MALE)
USING INDEX n:MALE(name)
where n.name="Matthew"
return n;
page 61:
page 62:
1
2
PROFILE MATCH(n) where n.name="Annie"
return n;
page 63:

page 64:
1
2
PROFILE MATCH(n) where n.name="Annie"
return n;
1
2
PROFILE MATCH(n:FEMALE) where n.name="Annie"
return n;

Chapter 4 - Getting Python and Neo4j to Talk Py2neo

page 80:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def executeCypherQueryInTransaction():
    print("Start - execution of Cypher Query in Transaction")
    #Connect to Graph
    graph=connectGraph()
    #begin a transaction
    tx = graph.cypher.begin()
    #Add statements to the transaction
    tx.append("CREATE (n:Node1{name:'John'}) RETURN n")
    tx.append("CREATE (n:Node1{name:'Russell'}) RETURN n")
    tx.append("CREATE (n:Node1{name:'Smith'}) RETURN n")
    #Finally commit the transaction and get results
    results = tx.commit()
    #Iterate over results and print the results
    for result in results:
        for record in result:
            print(record.n)
            print("End - execution of Cypher Query in Transaction")
page 90:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def testIndividualNodes(self):
    #Define a Node which we need to check
    bradley = Node('MALE','TEACHER',name = 'Bradley',
                                  surname = 'Green',
                                  age = 24,
                                  country = 'US')
    #Now get the Node from server
  # would be graph.run in newer py2neo (3.0+?)
    results = self.graph.cypher.execute('''MATCH (n) 
                                         WHERE n.name='Bradley'
                                         RETURN n as bradley''')
    #Both Nodes should be equal
    self.assertEqual(results[0].bradley, bradley)

Chapter 5 - Build RESTful Service with Flask and Py2neo

page 101:

Chapter 6 - Using Neo4j with Django and Neomodel

page 115:

Chapter 7 - Deploying Neo4j in Production

page 134:

page 135:
page 136:
page 137:

page 138:
page 139:
page 140:
page 141:
page 142:
page 144:
page 145:
page 146:
page 148:










[About] [Contact]