Persistent Collections

The persistent package provides two simple collections that are persistent and keep track of when they are mutated in place.

class persistent.mapping.PersistentMapping(dict=None, /, **kwargs)[source]

Bases: UserDict, Persistent

A persistent wrapper for mapping objects.

This class allows wrapping of mapping objects so that object changes are registered. As a side effect, mapping objects may be subclassed.

A subclass of PersistentMapping or any code that adds new attributes should not create an attribute named _container. This is reserved for backwards compatibility reasons.

clear()[source]

Remove all data from this dictionary.

Changed in version 4.5.2: If there was nothing to remove, this object is no longer marked as modified.

pop(k[, d]) v, remove specified key and return the corresponding value.[source]

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem()[source]

Remove an item.

Changed in version 4.5.2: No longer marks this object as modified if it was empty and an exception raised.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D[source]
update([E, ]**F) None.[source]

Changed in version 4.5.2: Now accepts arbitrary keyword arguments. In the special case of a keyword argument named b that is a dictionary, the behaviour will change.

class persistent.list.PersistentList(initlist=None)[source]

Bases: UserList, Persistent

A persistent wrapper for list objects.

Mutating instances of this class will cause them to be marked as changed and automatically persisted.

Changed in version 4.5.2: Using the clear method, or deleting a slice (e.g., del inst[:] or del inst[x:x]) now only results in marking the instance as changed if it actually removed items.

append(item)[source]

S.append(value) – append value to the end of the sequence

clear()[source]

Remove all items from the list.

Changed in version 4.5.2: Now marks the list as changed.

extend(other)[source]

S.extend(iterable) – extend sequence by appending elements from the iterable

insert(i, item)[source]

S.insert(index, value) – insert value before index

pop([index]) item -- remove and return item at index (default last).[source]

Raise IndexError if list is empty or index is out of range.

remove(item)[source]

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()[source]

S.reverse() – reverse IN PLACE