stormlibpp.node module

Work with storm:node objects in Python.

class stormlibpp.node.ItemContainer(**kwargs)

Bases: object

Hold key/value items in dict-like container.

Acts almost identically to a dict except:

- Missing items simply return None, not raise an error.
- Iterating over an ``ItemContainer`` returns key/value pairs instead
  of just the key.
- Keys must be strings.
    - Although technically non-string keys could be used, it messes
      up instantiation.
- The object's ``repr`` is the current classname and all items in the
  container as if the object was being instantiated - a la ``SimpleNamespace``.
  Meaning, subclasses get automatic repr support.

All default methods of a dict are supported, they are actually directly returned from the underlying dict thanks to __getattr__ magic. Meaning calling these methods operate on the items this container.

Supports obj['item'] (and obj['item'] = 'val') notation.

When “getting” an item with __getitem__, that doesn’t exist in the container, None is returned instead of raising an exception.

Calling dir on this object will only return names for items this object “holds” instead of all parts of this object.

Supports checking if an item is “held” via the in operator.

Supports iteration of items in the underlying dict. Each iteration returns a tuple of the item name followed by the item value.

Implements only magic methods, and all of them operate on the underlying SimpleNamespace.

To convert this object to a dict of the items it holds, call vars on an instance.


All keyword args passed at instantiation are added to the container as initial values. These are not required and no args passed just creates an empty container.


A nodes definition, the node’s form and primary value.

alias of tuple[str, str]


A valid syn:form value.


A packed node, this is what get’s sent from Storm to a Telepath endpoint.

Or what get’s returned from a Cortex’s Python APIs.

alias of tuple[tuple[str, str], NodeVals]

class stormlibpp.node.NodeVals

Bases: TypedDict

The items a Node can have in the second part of packed NodeTuple.

iden: str
nodedata: dict[str, Any]
props: dict[str, Any]
tagprops: dict[str, Any]
tags: dict[str, Any]
class stormlibpp.node.Props(**kwargs)

Bases: ItemContainer

Properties of a StormNode.

class stormlibpp.node.StormNode(form: str, value: Any, /, iden: str = '', tags: dict = {}, props: dict = {}, nodedata: dict = {}, tagprops: dict = {}, **kwargs)

Bases: object

A storm:node Storm object that is in a Python runtime.

It supports “unpacking” the node into this object, edits to the object, and repacking of the node to be sent back to Storm.

This node can be created purely from Python code rather than a packed storm:node object. Use __init__ directly instead of unpack. This allows the creation of a new node in Python that can be passed back to Storm.

The intent is to represent an object that can be read from and written back to a Cortex. It isn’t meant to provide the same API that a storm:node has in Storm.

addProp(propname: str, propval: Any) None
addProps(props: dict[str, Any]) None
addTag(tag, timestamps: tuple = (None, None)) None
addTags(tags, timestamps: tuple = (None, None)) None
property form: str

The form of this StormNode.

property nodevals

The NodeVals dict this Node would have in a NodeTuple.

pack() tuple[tuple[str, str], stormlibpp.node.NodeVals]
property props

The properties of this StormNode.

property tags

The tags of this StormNode.

classmethod unpack(packedtup: tuple[tuple[str, str], stormlibpp.node.NodeVals]) StormNode
property value: str

The value of this StormNode.

class stormlibpp.node.Tags(**kwargs)

Bases: ItemContainer

Tags of a StormNode.