I ended up creating a Model metaclass called ModelMeta that registers typed attributes.
See http://github.com/espeed/bulbs/blob/master/bulbs/model.py
In this case, typed attributes are the "properties" of the graph database, which are all subclasses of the Property class.
. https://github.com/espeed/bulbs/blob/master/bulbs/property.py
:
from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime
class Person(Node):
element_type = "person"
name = String(nullable=False)
age = Integer()
class Knows(Relationship):
label = "knows"
created = DateTime(default=current_datetime, nullable=False)
:
>>> from people import Person
>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> g.add_proxy("people", Person)
>>> james = g.people.create(name="James")
>>> james.eid
3
>>> james.name
'James'
>>> james = g.people.get(james.eid)
>>> james.age = 34
>>> james.save()
>>> nodes = g.people.index.lookup(name="James")
...