--- title: Itembase keywords: fastai sidebar: home_sidebar nb_path: "nbs/itembase.ipynb" ---
{% raw %}
{% endraw %}

Any data class in pyintegrators inherits from ItemBase. As its name suggests 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.

{% raw %}

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 pyintegrators, you will often use ItemBase.add_edge

{% endraw %} {% raw %}
{% endraw %} {% raw %}

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.

{% endraw %} {% raw %}

class ItemBase[source]

ItemBase(uid=None)

Provides a base class for all items. All items in the schema inherit from this class, and it provides some basic functionality for consistency and to enable easier usage.

{% endraw %} {% raw %}
{% endraw %} {% raw %}

ItemBase.add_edge[source]

ItemBase.add_edge(name, val)

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

{% endraw %} {% raw %}

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.

{% endraw %} {% raw %}

ItemBase.expand[source]

ItemBase.expand(api)

Expands a node (retrieves all directly connected nodes ands adds to object).

{% endraw %} {% raw %}

ItemBase.inherit_funcs[source]

ItemBase.inherit_funcs(other)

This function can be used to inherit new functionalities from a subclass. This is a patch to solve the fact that python does provide extensions of classes that are defined in a different file that are dynamic enough for our use case.

{% endraw %}

Usage

With the ItemBase 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 an email item and create it in the pod.

{% raw %}
item = EmailMessage.from_data(content="example content field")
{% endraw %}