Nodes are defined by subclassing StructuredNode. Data members intended for storage must be defined using neomodel property objects (e.g., StringProperty, IntegerProperty, UniqueIdProperty).
Relationships are defined using RelationshipTo, RelationshipFrom, or Relationship objects.
RelationshipTo and RelationshipFrom specify a direction for traversal.- Use
Relationship for bi-directional relationships to avoid defining two complementary relationships in Python.
neomodel automatically creates a label for each StructuredNode class in the database along with any specified indexes and constraints.
from neomodel import (get_config, StructuredNode, StringProperty, IntegerProperty,
UniqueIdProperty, RelationshipTo)
config = get_config()
config.database_url = 'bolt://neo4j_username:neo4j_password@localhost:7687'
class Country(StructuredNode):
code = StringProperty(unique_index=True, required=True)
class City(StructuredNode):
name = StringProperty(required=True)
country = RelationshipTo(Country, 'FROM_COUNTRY')
class Person(StructuredNode):
uid = UniqueIdProperty()
name = StringProperty(unique_index=True)
age = IntegerProperty(index=True, default=0)
country = RelationshipTo(Country, 'IS_FROM')
city = RelationshipTo(City, 'LIVES_IN')