Persistence and Serialization Modules
copyreg
Registers reduction functions used by pickle and copying operations. A reduction describes how to reconstruct a value; it is not a security filter for incoming pickle data. Registration changes shared process state, so libraries should avoid conflicting registrations and tests should restore any previous entry.
Formal Syntax & Structure
python syntaxpython
import copyregReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import copyregimport copy
class Item: def __init__(self, value): self.value = value
try: copyreg.pickle(Item, lambda item: (Item, (item.value,))) original = Item(7) clone = copy.copy(original) print(clone.value, clone is original)finally: copyreg.dispatch_table.pop(Item, None)