Feineigle.com - Building Web Applications with Python and Neo4j

Home · Book Reports · 2016 · Building Web Applications With Python and Neo4j

Published: January 1, 2015 (9 years 4 months ago.)
Updated:   November 20, 2016 (7 years 4 months ago.)
Tags:  Neo4j · Python · Software

The book in...
One sentence:
The basics of neo4j, cypher, and py2neo plus some of the technical options, but focuses on Neo4j 2.x.

Five sentences:
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.

designates my notes. / designates important.

Uses neo4j 2.2


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/spanroduction options.

Chapter 1 - Your First Query with Neo4j

page 14:

Chapter 2 - Querying the Graph with Cypher

page 24:
page 25:
MATCH (x:MALE) WHERE x.age is NOT NULL and x.name is NOT NULL RETURN
count(DISTINCT x.name);
page 32:
MATCH (n:MALE {name: "Andrew", age:24}) remove n.age return n;
page 36:
where n.name IN["John","Andrew"] and n.age is Not Null
return n;
where n.name =~"J.*"
return n;
page 37:
MATCH (n)return n ORDER by n.name, n.age SKIP 3 LIMIT 2;
page 38:
MATCH (x{ name: "Bradley" })--(y)-->()
WITH y, count(*) AS cnt
WHERE cnt> 1
MATCH (x:MALE)-[:FRIEND]->() return x.name, labels(x)
MATCH (x:FEMALE)-[:FRIEND]->()return x.name, labels(x);
page 41:
MATCH (x{name:"Bradley"})-[:FRIEND]->(friend)<-[:FRIEND]-(otherFriend)
return distinct friend.name as CommonFriend;
Match (me{name:"Bradley"})-[r:FRIEND]-(myFriend),(myFriend)-[:FRIEND]-(otherFriend)
where NOT (me)-[:FRIEND]-(otherFriend)
return otherFriend.name as NotMyFriends;
page 42:
MATCH (movie:MOVIE)<-[r:HAS_RATED*0..]-(person)
return movie.name as Movie, count(person)-1 as
countOfRatings order by countOfRatings;
page 43:
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:
MATCH (f:FEMALE {name: "Sheena"})
return f;
MATCH (f:FEMALE {name: "Sheena"})
return f;
page 59:
page 60:
where n.name="Matthew"
return n;
page 61:
page 62:
PROFILE MATCH(n) where n.name="Annie"
return n;
page 63:
page 64:
PROFILE MATCH(n) where n.name="Annie"
return n;
PROFILE MATCH(n:FEMALE) where n.name="Annie"
return n;

Chapter 4 - Getting Python and Neo4j to Talk Py2neo

page 80:
def executeCypherQueryInTransaction():
	print("Start - execution of Cypher Query in Transaction")
	#Connect to Graph
	#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("End - execution of Cypher Query in Transaction")
page 90:
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: