Builtin Model Types

Spectate provides a number of builtin model types that you can use out of the box. For most users these built-in types should be enough, however if you’re adventurous, then you can create your own Custom Models.

Dictionary

The Dict model is a subclass of Python’s standard dict. This will produce events when the value of a key in the dictionary changes or is deleted. This will result when calling methods like dict.update() and dict.pop(), but also when using the normal syntax to set or delete an item. Events produced by Dict have the following fields:

Field

Description

key

The key in the dict model that changed.

old

  • The value that was present in the key before the change

  • Is Undefined if the index was not present.

new

  • The value that this is now present after the change

  • Is Undefined if the index was deleted.

List

The List model is a subclass of Python’s standard list. This model will produce events when an element of the list changes or an element changes from one position to another. This may happen when calling methods like list.append() or list.remove(), but also when using the normal syntax to set or delete an item. Events produced by List have the following keys:

Field

Description

index

The index in the dict model that changed.

old

  • The value that was present before the change

  • Is Undefined if the key was not present.

new

  • The value that this is now present after the change

  • Is Undefined if the key was deleted.

Set

The Set model is a subclass of Python’s standard set. This model will produce events when an element of the set changes. This may happen when calling methods like set.add() or set.discard(). Events produced by Set have the following keys:

Field

Description

old

A set of values that were removed due to the change.

new

A set of the values that were added due to the change.

Object

The Object model is a subclass of Python’s standard object. This model will produce events when an attribute of the object changes or is deleted. This may happen when using setattr() or delattr(), but also when using the normal syntax to set or delete attributes. Events produced by Object have the following keys:

Field

Description

attr

The attribute in the model that changed.

old

  • The value that was present before the change

  • Is Undefined if the attribute was not present.

new

  • The value that this is now present after the change

  • Is Undefined if the key was deleted.