Skip to main content
The pickle module implements binary protocols for serializing and de-serializing Python objects.

Module Import

Basic Operations

dumps() / loads() - Serialize to/from Bytes

dump() / load() - Serialize to/from File

Pickling Complex Objects

Protocol Versions

Practical Examples

Cache Expensive Computation

Save Program State

Security Warning: Never unpickle data from untrusted sources. Pickle can execute arbitrary code during unpickling.
For data interchange, prefer JSON. Use pickle only for trusted data and Python-to-Python communication.

json

JSON encoding/decoding

shelve

Python object persistence