Any data class in pymemri inherits from Item. It is a base class for items with some handy functionalities to create new items and edges, retrieve all edges to other items, and sync with the pod.

class Edge[source]

Edge(source, target, _type, label=None, sequence=None, created=False, reverse=True)

Edges makes a link between two ItemBase Items. You won't use this class a lot in practice, as edges are abstracted away for normal users. When items are retrieved from the database, the edges are parsed automatically. When you add an edge between to items within pymemri, you will often use ItemBase.add_edge

Edge.traverse[source]

Edge.traverse(start)

We can traverse an edge starting from the source to the target or vice versa. In practice we often call item.some_edge_type, which calls item.traverse(edgetype), which in turn calls this function.

ITEMBASE_PROPERTIES = ["dateAccessed", "dateCreated", "dateModified", "deleted", "externalId", "itemDescription",
                     "starred", "version", "id", "importJson", "name", "repository", "icon", "bundleImage",
                     "runDestination", "pluginClass"]

class Item[source]

Item(dateAccessed:str=None, dateCreated:str=None, dateModified:str=None, deleted:str=None, externalId:str=None, itemDescription:str=None, starred:str=None, version:str=None, id:str=None, importJson:str=None, pluginClass:str=None, changelog:list=None, label:list=None, genericAttribute:list=None, measure:list=None, sharedWith:list=None) :: ItemBase

Item is the baseclass for all of the data classes.

ItemBase.add_edge[source]

ItemBase.add_edge(name, val)

Creates an edge of type name and makes it point to val

ItemBase.is_expanded[source]

ItemBase.is_expanded()

returns whether the node is expanded. An expanded node retrieved nodes that are directly connected to it from the pod, and stored their values via edges in the object.

Usage

With the Item and Edge classes we can create an item and its surrounding graph. The schema is defined in schema.py, in general we want to use the from_data staticmethod to generate new items, because it ensures that edges are linked from both the source and the target object. Let's make a new item and add it to the pod.

class MyItem(Item):
    properties = Item.properties + ["name", "age"]
    edges = Item.edges + ["friend"]
    def __init__(self, name=None, age=None,friend=None, **kwargs):
        super().__init__(**kwargs)
        self.name = name
        self.age = age
        self.friend = fried if friend is not None else []
from pymemri.pod.client import PodClient
client = PodClient()
assert client.add_to_schema(MyItem(name="abc", age=1))
x = MyItem(name="me", age=30)
x.add_edge("friend", MyItem(name="my friend", age=31))

We can now create our MyItem, as a side-effect of creating it, it will receive an id

print(x.id)
None
assert client.create(x)
print(x.id)
bfec09ee3c0eee83e4fb4a63674704f5
y = client.get(x.id)
assert len(y.friend) > 0
assert y.friend[0].name == "my friend"
assert y.name == "me"
assert y.age == 30

# One year later
y.age = 31
y.add_edge("friend", MyItem(name="my friend2", age=29))
y.update(client)
assert y.age == 31
assert len(y.friend) == 2
'my friend'