Pickle
Dan Tobias (Talk | contribs) (→Links) |
Dan Tobias (Talk | contribs) (→Sample data) |
||
Line 19: | Line 19: | ||
== Sample data == | == Sample data == | ||
− | * [ | + | * [https://www.dan.info/sampledata/pickle/data0.pickle Protocol 0] |
− | * [ | + | * [https://www.dan.info/sampledata/pickle/data1.pickle Protocol 1] |
− | * [ | + | * [https://www.dan.info/sampledata/pickle/data2.pickle Protocol 2] |
− | * [ | + | * [https://www.dan.info/sampledata/pickle/data3.pickle Protocol 3] |
− | * [ | + | * [https://www.dan.info/sampledata/pickle/data4.pickle Protocol 4] |
== Links == | == Links == |
Revision as of 00:00, 12 February 2020
- I don't want a pickle; Just want to ride on my motorsickle.
- -- Arlo Guthrie
Pickle is a serialization format used by the Python programming language. There have been several different protocols, introduced in different versions of Python. Newer Python versions support the earlier protocols, but data using them wouldn't be compatible with earlier Python versions not supporting that version of the protocol. Pickle is Python-specific, so data intended to be used across different programs in different programming languages would be better off using a more standardized format such as JSON (which is also supported by a standard Python library), but Pickle is optimized for Python, supporting greater speed and compactness and able to encode just about anything that can be stored in a Python variable, including the quirkier Python constructs which might not be easy to represent in other formats. By the same token, however, this makes Pickle a potentially dangerous format since it can encapsulate such things as functions which do harmful things, allowing it to become a medium for transmitting trojan horse programs. For this reason, it is not a good idea to use Pickle as a format for exchanging data from untrusted sources, or as input/output in public-facing APIs.
Pickle data may be saved to a file, a database, or a network; it does not necessarily have a distinctive file extension, but .pickle is sometimes used.
Pickle protocols
- 0: Text-based format used in early Python versions
- 1: Binary format used in early Python versions
- 2: Introduced in Python 2.3; better support for new-style classes
- 3: Introduced in Python 3.0; supports new Python 3.0 types
- 4: Introduced in Python 3.4; some improvements to efficiency, and added support for more data types