Jump to content

Pickle (Python)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pi Delport (talk | contribs) at 19:04, 15 June 2012 (Not all types can be pickled automatically, but users can register reduction/construction functions). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In the computer programming language Python, pickle is the standard mechanism for object serialization; pickling is the common term among Python programmers for serialization (unpickling for deserializing). Pickle uses a simple stack-based virtual machine that records the instructions used to reconstruct the object. This makes pickle vulnerable to security risks by malformed or maliciously constructed data, that may cause the deserializer to import arbitrary modules and instantiate any object[1][2]. Not all object types can be pickled automatically, especially ones that hold operating system resources like file handles, but users can register custom "reduction" and construction functions to support the pickling and unpickling of arbitrary types.

Pickle was originally implemented as the pure Python pickle module, but the cPickle module (also a built-in) offers improved performance (up to 1000 times faster[1]).

References