Spectate: Track Mutable Data Changes

1.0.1 · active · verified Fri Apr 17

Spectate (v1.0.1) is a Python library designed to track changes to mutable data types, providing undo/redo capabilities for operations on objects like dictionaries and lists. It achieves this by wrapping functions that modify tracked objects, recording events for each change. The library is currently feature-complete and in maintenance mode, with a slow release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `spectate.track` to observe changes to a dictionary, and then `undo` and `redo` those changes. The `@track` decorator wraps the `add_entry` function, automatically recording each modification to the dictionary `a`.

from spectate import track, undo, redo

a = {}

@track(a)
def add_entry(key, value):
    a[key] = value

add_entry('x', 1)
add_entry('y', 2)
print(f"Initial state: {a}")

undo()
print(f"After first undo: {a}")

undo()
print(f"After second undo: {a}")

redo()
print(f"After first redo: {a}")

redo()
print(f"After second redo: {a}")

view raw JSON →