Python Pickle Module Constants

The pickle module provides constants that can be used while calling the pickle module functions like load(), loads(), dump() and dumps(). The example prints the value of the constants pickle.HIGHEST_PROTOCOL and pickle.DEFAULT_PROTOCOL.

Pickle Updated 18 Dec 2018 1 min read

The constants provided by the Python Pickle Module

Constant NameDescription
Pickle Protocol Version Related: - These constants are to represent the pickle protocol versions. - Higher the Version Number more refined and improvised serialization features are available to the pickling process. - Lower the version number, the pickling and the related data exchange is supported with the earlier python versions. - These constants are typically used while making the pickle module function calls load(), loads(),dump() and dumps()
pickle.HIGHEST_PROTOCOLReturns the highest pickle protocol version of the Python installation.
pickle.DEFAULT_PROTOCOLReturns the default pickle protocol version of the Python installation.

Example

python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28)

[Clang 6.0 (clang-600.0.57)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import pickle

>>> pickle.HIGHEST_PROTOCOL

4

>>> pickle.DEFAULT_PROTOCOL

3

>>>