Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 1.26 KB

README.md

File metadata and controls

52 lines (37 loc) · 1.26 KB

paragraph

cms for labeled property graphs

Usage example from neo4j:

>>> from paragraph.NeoGraphDB import NeoGraphDB
>>> db = NeoGraphDB()
>>> alice = db.add_node('Person', name='alice')

Alice is a node. Nodes have a unique id and labels:

>>> alice
(Person ... alice)

But a note also stores properties like a dictionary:

>>> dict(alice)
{'_id': '...', 'name': 'alice'}
>>> alice.id == alice['_id']
True

Why does id show up in the node properties, but not the labels? Because at least for neo4j labels are stored on nodes anyhow, but id needs to be stored "manually", hence the property with the special marker for technical attributes, the underscore "_".

Now lets link alice to bob:

>>> bob = db.add_node('Person', name='bob')
>>> edge = db.add_edge(alice, 'friend_of', bob, foo='bar')
>>> edge.id
'...'
>>> edge.source == alice
True
>>> edge.target == bob
True
>>> edge.reltype
'friend_of'

And again, all other properties are stored dictionary-style in the edge:

>>> edge
(Person ... alice) --[friend_of]--> (Person ... bob)
>>> dict(edge)
{'_id': '...', 'foo': 'bar'}

Lets move from alice one hop outwards:

>>> nodes = alice.oN('friend_of').nodes
>>> nodes == {bob}
True