Persistence and Serialization Modules

pickletools

Inspects the instruction stream of pickle data using dis or genops without reconstructing the original objects. Useful for investigating serialization formats. Inspection is not a guarantee of harmless data and does not eliminate resource exhaustion risks. Use bounded trusted bytes in examples.

Formal Syntax & Structure

python syntaxpython
import pickletools

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import pickle,pickletoolsdata = pickle.dumps([1, 2], protocol=4)print(list(pickletools.genops(data))[-1][0].name)
Python Reference