Preferred (or most common) file extension for a Python pickle

PythonRestFilenamesMime TypesPickle

Python Problem Overview


At times, I've seen .pickle, .pck, .pcl, and .db for files that contain Python pickles, but I am unsure what is the most common or best practice. I know that the latter three extensions are also used for other things.

The related question is: What MIME type is preferred for sending pickles between systems using a REST API?

Python Solutions


Solution 1 - Python

Python 2

From the Python 2 documentation, while serializing (i.e. writing to a pickle file), use:

output = open('data.pkl', 'wb')

I would choose .pkl as the extension when using Python 2.

Python 3

The example in the Python 3 documentation now uses .pickle as the file extension for serialization:

with open('data.pickle', 'wb') as f:
    pickle.dump(...)

The MIME type preferred for sending pickles from martineau's comment below:

> application/octet-stream

See https://stackoverflow.com/questions/13223855/what-is-the-http-content-type-to-use-for-a-blob-of-bytes

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRaymond HettingerView Question on Stackoverflow
Solution 1 - PythonTheoretiCALView Answer on Stackoverflow