graphrecords.plugins#

Plugin authoring surface for the graphrecords library.

Module Attributes

Change

A type alias for a change a plugin hook may return.

Changes

A type alias for the changes a plugin hook may return.

Classes

AddEdges(batch)

The payload of a change adding edges.

AddEdgesInGroup(batch, group_index)

The payload of a change adding edges in a group.

AddEdgesToGroup(edge_indices, group_index)

The payload of a change adding edges to a group.

AddGroup(group_index)

The payload of a change adding a group.

AddNodes(batch)

The payload of a change adding nodes.

AddNodesInGroup(batch, group_index)

The payload of a change adding nodes in a group.

AddNodesToGroup(node_indices, group_index)

The payload of a change adding nodes to a group.

Clear()

The payload of a change clearing the GraphRecord.

EdgeBatch(edges)

A batch of edges carried by a change payload.

EdgeBatchIterator()

An iterator over the edges of a batch.

FreezeSchema()

The payload of a change freezing the schema.

NodeBatch(nodes)

A batch of nodes carried by a change payload.

NodeBatchIterator()

An iterator over the nodes of a batch.

Plugin()

Base class for GraphRecord plugins.

RemoveEdgeAttributes(edge_indices, ...)

The payload of a change removing edge attributes.

RemoveEdges(edge_indices)

The payload of a change removing edges.

RemoveEdgesFromGroup(edge_indices, group_index)

The payload of a change removing edges from a group.

RemoveGroups(group_indices)

The payload of a change removing groups.

RemoveNodeAttributes(node_indices, ...)

The payload of a change removing node attributes.

RemoveNodes(node_indices)

The payload of a change removing nodes.

RemoveNodesFromGroup(node_indices, group_index)

The payload of a change removing nodes from a group.

ReplaceEdgeAttributes(edge_indices, attributes)

The payload of a change replacing edge attributes.

ReplaceNodeAttributes(node_indices, attributes)

The payload of a change replacing node attributes.

SetEdgeAttributes(edge_indices, attributes)

The payload of a change setting edge attributes.

SetNodeAttributes(node_indices, attributes)

The payload of a change setting node attributes.

SetSchema(schema)

The payload of a change setting the schema.

UnfreezeSchema()

The payload of a change unfreezing the schema.

class AddEdges(batch)[source]#

Bases: object

The payload of a change adding edges.

property batch: EdgeBatch#

The edges that are added.

Returns:

EdgeBatch – The edges that are added.

class AddEdgesInGroup(batch, group_index)[source]#

Bases: object

The payload of a change adding edges in a group.

property batch: EdgeBatch#

The edges that are added.

Returns:

EdgeBatch – The edges that are added.

property group_index: str | int#

The group the edges are added in.

Returns:

GroupIndex – The group the edges are added in.

class AddEdgesToGroup(edge_indices, group_index)[source]#

Bases: object

The payload of a change adding edges to a group.

property edge_indices: List[EdgeIndex]#

The edges that are added.

Returns:

List[EdgeIndex] – The edges that are added.

property group_index: str | int#

The group the edges join.

Returns:

GroupIndex – The group the edges join.

class AddGroup(group_index)[source]#

Bases: object

The payload of a change adding a group.

property group_index: str | int#

The group that is added.

Returns:

GroupIndex – The group that is added.

class AddNodes(batch)[source]#

Bases: object

The payload of a change adding nodes.

property batch: NodeBatch#

The nodes that are added.

Returns:

NodeBatch – The nodes that are added.

class AddNodesInGroup(batch, group_index)[source]#

Bases: object

The payload of a change adding nodes in a group.

property batch: NodeBatch#

The nodes that are added.

Returns:

NodeBatch – The nodes that are added.

property group_index: str | int#

The group the nodes are added in.

Returns:

GroupIndex – The group the nodes are added in.

class AddNodesToGroup(node_indices, group_index)[source]#

Bases: object

The payload of a change adding nodes to a group.

property group_index: str | int#

The group the nodes join.

Returns:

GroupIndex – The group the nodes join.

property node_indices: List[str | int]#

The nodes that are added.

Returns:

List[NodeIndex] – The nodes that are added.

Change#

A type alias for a change a plugin hook may return.

alias of AddNodes | AddNodesInGroup | AddEdges | AddEdgesInGroup | RemoveNodes | RemoveEdges | SetNodeAttributes | ReplaceNodeAttributes | RemoveNodeAttributes | SetEdgeAttributes | ReplaceEdgeAttributes | RemoveEdgeAttributes | AddGroup | RemoveGroups | AddNodesToGroup | RemoveNodesFromGroup | AddEdgesToGroup | RemoveEdgesFromGroup | SetSchema | FreezeSchema | UnfreezeSchema | Clear

Changes#

A type alias for the changes a plugin hook may return.

alias of AddNodes | AddNodesInGroup | AddEdges | AddEdgesInGroup | RemoveNodes | RemoveEdges | SetNodeAttributes | ReplaceNodeAttributes | RemoveNodeAttributes | SetEdgeAttributes | ReplaceEdgeAttributes | RemoveEdgeAttributes | AddGroup | RemoveGroups | AddNodesToGroup | RemoveNodesFromGroup | AddEdgesToGroup | RemoveEdgesFromGroup | SetSchema | FreezeSchema | UnfreezeSchema | Clear | List[AddNodes | AddNodesInGroup | AddEdges | AddEdgesInGroup | RemoveNodes | RemoveEdges | SetNodeAttributes | ReplaceNodeAttributes | RemoveNodeAttributes | SetEdgeAttributes | ReplaceEdgeAttributes | RemoveEdgeAttributes | AddGroup | RemoveGroups | AddNodesToGroup | RemoveNodesFromGroup | AddEdgesToGroup | RemoveEdgesFromGroup | SetSchema | FreezeSchema | UnfreezeSchema | Clear]

class Clear[source]#

Bases: object

The payload of a change clearing the GraphRecord.

class EdgeBatch(edges)[source]#

Bases: object

A batch of edges carried by a change payload.

__iter__()[source]#

Iterates over the edges of the batch.

Return type:

EdgeBatchIterator

Returns:

EdgeBatchIterator – An iterator over the edges.

__len__()[source]#

Counts the edges of the batch.

Return type:

int

Returns:

int – The number of edges.

attribute_values(attribute_name)[source]#

Collects the value of one attribute across the edges that carry it.

Parameters:

attribute_name (AttributeName) – The name of the attribute to read.

Return type:

List[Tuple[Union[str, int], Union[str, int], Union[str, int, float, bool, datetime, timedelta, None]]]

Returns:

List[Tuple[NodeIndex, NodeIndex, Value]]

The source node index, target

node index and value of every edge that carries the attribute.

is_empty()[source]#

Checks whether the batch holds no edges.

Return type:

bool

Returns:

bool – True if the batch is empty, otherwise False.

class EdgeBatchIterator[source]#

Bases: object

An iterator over the edges of a batch.

__iter__()[source]#

Returns the iterator itself.

Return type:

EdgeBatchIterator

Returns:

EdgeBatchIterator – The iterator itself.

__next__()[source]#

Returns the next edge of the batch.

Return type:

Tuple[Union[str, int], Union[str, int], Dict[Union[str, int], Union[str, int, float, bool, datetime, timedelta, None]]]

Returns:

Tuple[NodeIndex, NodeIndex, Attributes]

The source node index, target

node index and attributes of the edge.

class FreezeSchema[source]#

Bases: object

The payload of a change freezing the schema.

class NodeBatch(nodes)[source]#

Bases: object

A batch of nodes carried by a change payload.

__iter__()[source]#

Iterates over the nodes of the batch.

Return type:

NodeBatchIterator

Returns:

NodeBatchIterator – An iterator over the nodes.

__len__()[source]#

Counts the nodes of the batch.

Return type:

int

Returns:

int – The number of nodes.

attribute_values(attribute_name)[source]#

Collects the value of one attribute across the nodes that carry it.

Parameters:

attribute_name (AttributeName) – The name of the attribute to read.

Return type:

List[Tuple[Union[str, int], Union[str, int, float, bool, datetime, timedelta, None]]]

Returns:

List[Tuple[NodeIndex, Value]]

The index and value of every node that

carries the attribute.

is_empty()[source]#

Checks whether the batch holds no nodes.

Return type:

bool

Returns:

bool – True if the batch is empty, otherwise False.

class NodeBatchIterator[source]#

Bases: object

An iterator over the nodes of a batch.

__iter__()[source]#

Returns the iterator itself.

Return type:

NodeBatchIterator

Returns:

NodeBatchIterator – The iterator itself.

__next__()[source]#

Returns the next node of the batch.

Return type:

Tuple[Union[str, int], Dict[Union[str, int], Union[str, int, float, bool, datetime, timedelta, None]]]

Returns:

Tuple[NodeIndex, Attributes] – The index and attributes of the node.

class Plugin[source]#

Bases: object

Base class for GraphRecord plugins.

Every hook is optional: a GraphRecord calls a hook only when the plugin defines it. A pre_ hook returns what the GraphRecord applies in place of the change it received: None keeps that change, a change or a list of changes replaces it, and an empty list drops it. initialize and finalize return changes the same way, but receive no change, so None means no changes. A post_ hook observes the GraphRecords before and after the applied changes together with the change that was applied and must return None. The two GraphRecords bracket every change applied in the call, not only the change the hook received. The hooks are declared for type checkers only, which keeps a plugin free of the hooks it does not implement and keeps a GraphRecord from building payloads nobody reads.

class RemoveEdgeAttributes(edge_indices, attribute_names)[source]#

Bases: object

The payload of a change removing edge attributes.

property attribute_names: List[str | int]#

The names of the removed attributes.

Returns:

List[AttributeName] – The names of the removed attributes.

property edge_indices: List[EdgeIndex]#

The edges the attributes are removed from.

Returns:

List[EdgeIndex] – The edges the attributes are removed from.

class RemoveEdges(edge_indices)[source]#

Bases: object

The payload of a change removing edges.

property edge_indices: List[EdgeIndex]#

The edges that are removed.

Returns:

List[EdgeIndex] – The edges that are removed.

class RemoveEdgesFromGroup(edge_indices, group_index)[source]#

Bases: object

The payload of a change removing edges from a group.

property edge_indices: List[EdgeIndex]#

The edges that are removed.

Returns:

List[EdgeIndex] – The edges that are removed.

property group_index: str | int#

The group the edges leave.

Returns:

GroupIndex – The group the edges leave.

class RemoveGroups(group_indices)[source]#

Bases: object

The payload of a change removing groups.

property group_indices: List[str | int]#

The groups that are removed.

Returns:

List[GroupIndex] – The groups that are removed.

class RemoveNodeAttributes(node_indices, attribute_names)[source]#

Bases: object

The payload of a change removing node attributes.

property attribute_names: List[str | int]#

The names of the removed attributes.

Returns:

List[AttributeName] – The names of the removed attributes.

property node_indices: List[str | int]#

The nodes the attributes are removed from.

Returns:

List[NodeIndex] – The nodes the attributes are removed from.

class RemoveNodes(node_indices)[source]#

Bases: object

The payload of a change removing nodes.

property node_indices: List[str | int]#

The nodes that are removed.

Returns:

List[NodeIndex] – The nodes that are removed.

class RemoveNodesFromGroup(node_indices, group_index)[source]#

Bases: object

The payload of a change removing nodes from a group.

property group_index: str | int#

The group the nodes leave.

Returns:

GroupIndex – The group the nodes leave.

property node_indices: List[str | int]#

The nodes that are removed.

Returns:

List[NodeIndex] – The nodes that are removed.

class ReplaceEdgeAttributes(edge_indices, attributes)[source]#

Bases: object

The payload of a change replacing edge attributes.

property attributes: Dict[str | int, str | int | float | bool | datetime | timedelta | None]#

The attributes the edges end up with.

Returns:

Attributes – The attributes the edges end up with.

property edge_indices: List[EdgeIndex]#

The edges the attributes are replaced on.

Returns:

List[EdgeIndex] – The edges the attributes are replaced on.

class ReplaceNodeAttributes(node_indices, attributes)[source]#

Bases: object

The payload of a change replacing node attributes.

property attributes: Dict[str | int, str | int | float | bool | datetime | timedelta | None]#

The attributes the nodes end up with.

Returns:

Attributes – The attributes the nodes end up with.

property node_indices: List[str | int]#

The nodes the attributes are replaced on.

Returns:

List[NodeIndex] – The nodes the attributes are replaced on.

class SetEdgeAttributes(edge_indices, attributes)[source]#

Bases: object

The payload of a change setting edge attributes.

property attributes: Dict[str | int, str | int | float | bool | datetime | timedelta | None]#

The attributes that are set.

Returns:

Attributes – The attributes that are set.

property edge_indices: List[EdgeIndex]#

The edges the attributes are set on.

Returns:

List[EdgeIndex] – The edges the attributes are set on.

class SetNodeAttributes(node_indices, attributes)[source]#

Bases: object

The payload of a change setting node attributes.

property attributes: Dict[str | int, str | int | float | bool | datetime | timedelta | None]#

The attributes that are set.

Returns:

Attributes – The attributes that are set.

property node_indices: List[str | int]#

The nodes the attributes are set on.

Returns:

List[NodeIndex] – The nodes the attributes are set on.

class SetSchema(schema)[source]#

Bases: object

The payload of a change setting the schema.

property schema: Schema#

The schema that is set.

Returns:

Schema – The schema that is set.

class UnfreezeSchema[source]#

Bases: object

The payload of a change unfreezing the schema.