Persistence and Serialization Modules
pickle
Serializes Python object graphs to bytes and reconstructs them, preserving many shared references and cycles. Formats and compatible classes matter when sharing data across versions. Unpickling can execute code: only deserialize data from trusted sources, and prefer interoperable formats for data exchange.
Formal Syntax & Structure
python syntaxpython
import pickleReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import pickleoriginal = {"scores": [2, 4]}data = pickle.dumps(original)print(pickle.loads(data))