Last Updated: May 22, 2026
pickle is Python's built-in serializer for Python objects. Where JSON converts to a small fixed set of types that any language can read, pickle captures Python objects as Python objects: lists with nested dicts, custom classes, complex numbers, datetime values, even most of your own instances, all in one call. The price is that the result is Python-only and that loading an untrusted pickle can run arbitrary code on your machine. This lesson covers what pickle does, the four functions used most often, what's safe to pickle and what isn't, the five protocols, the safer alternatives, and the security model that matters before exposing pickle to anything you don't control.