Pickle
Dan Tobias (Talk | contribs) (Created page with "{{FormatInfo |formattype=electronic |subcat=Serialization |extensions={{ext|pickle}} }} :''I don't want a pickle; Just want to ride on my motorsickle.'' :-- [http://www.youtub...") |
Dan Tobias (Talk | contribs) (wikidata) |
||
(3 intermediate revisions by one user not shown) | |||
Line 3: | Line 3: | ||
|subcat=Serialization | |subcat=Serialization | ||
|extensions={{ext|pickle}} | |extensions={{ext|pickle}} | ||
+ | |wikidata={{wikidata|Q28206437}} | ||
}} | }} | ||
:''I don't want a pickle; Just want to ride on my motorsickle.'' | :''I don't want a pickle; Just want to ride on my motorsickle.'' | ||
Line 8: | Line 9: | ||
'''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''' 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 == | == Pickle protocols == | ||
Line 17: | Line 20: | ||
== 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 == | ||
* [https://docs.python.org/2/library/pickle.html Python 2 Pickle library docs] | * [https://docs.python.org/2/library/pickle.html Python 2 Pickle library docs] | ||
* [https://docs.python.org/3/library/pickle.html Python 3 Pickle library docs] | * [https://docs.python.org/3/library/pickle.html Python 3 Pickle library docs] | ||
+ | * [http://legacy.python.org/dev/peps/pep-0307/ PEP 307: Extensions to the Pickle protocol (2.2)] | ||
+ | * [http://legacy.python.org/dev/peps/pep-3154/ PEP 3154: Pickle protocol version 4] | ||
* [[Wikipedia:Pickle (Python)|Wikipedia article]] | * [[Wikipedia:Pickle (Python)|Wikipedia article]] | ||
* [http://stackoverflow.com/questions/8968884/python-serialization-why-pickle Why Pickle?] | * [http://stackoverflow.com/questions/8968884/python-serialization-why-pickle Why Pickle?] | ||
* [http://python.about.com/od/pythonstandardlibrary/a/pickle_intro.htm Pickle intro] | * [http://python.about.com/od/pythonstandardlibrary/a/pickle_intro.htm Pickle intro] | ||
* [https://blog.nelhage.com/2011/03/exploiting-pickle/ Exploiting Misuse of Python's "Pickle"] | * [https://blog.nelhage.com/2011/03/exploiting-pickle/ Exploiting Misuse of Python's "Pickle"] |
Latest revision as of 00:01, 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.
[edit] 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