Example code for creating models with relationships, and interacting with data using both object and cypher queries.

Introduction:
This tutorial will step you through the use-case, design, and development of the solution using Python, neo4j, and neomodel. There will be code examples along the way.
Pre-requisites:
Though not required, it will be helpful if you would have gone through neomodel documentation. You could download code for this tutorial from my repo.
Install Neo4J and run it with default configurations (bolt://localhost:7687). Change the password to “password”
Install Python. Install neomodel using command pip install neomodel
Use-case:
As a leader, I want the ability to track and manage the skills, and proficiencies on those skills over years, for the team members in a project.
Database Design:
The problem statement above gives indication about few entities and their relationship — all bolded. The database should have an entity for storing information about team member, another one for different skills. Proficiency is a relationship between team member and skill, and it needs to capture the proficiency level for a year.
A graph database like neo4j fits very well for this scenario. And neomodel makes it easier for Python developers to create these structures in neo4j. Here is the example code (taken from model.py). Please refer the code in repo for comments explaining important parts of the code.
class Skill(StructuredNode):
name = StringProperty(required=True, unique_index=True) # structure to define relationship attributes between Team Member and Skill
class ProficiencyRel(StructuredRel):
year = IntegerProperty(required=True)
score = FloatProperty(required=True)
name = AliasProperty(to='year')
class TeamMember(StructuredNode):
first_name = StringProperty(required=True)
last_name = StringProperty(required=True)
name = StringProperty(required=True)
email: object = EmailProperty(required=True, unique_index=True)
skill = Relationship(Skill,
'PROFICIENCY_FOR',
cardinality=ZeroOrMore,
model=ProficiencyRel)
def pre_save(self):
self.email = self.first_name + "." + self.last_name + "@" +
"acme.com"
self.name = self.last_name + "," + self.first_name
Application:
The code in app.py shows how to interact with neo4j database using options provided by neomodel and cypher. There are almost 100 lines of code showing different features of neomodel and python to save and retrieve data from neo4j. I’m not copying the code here to keep it concise, and hope that you find the comments in code useful to understand the different features.
Conclusion:
I was looking for some programming options to work with neo4j. Based on my situation, I had to go for Python. I found that neomodel made it easy to work with neo4j. I created some examples. I hope you found it useful and it introduced you to developing applications using neo4j, Python, and neomodel.