What is the PKL file format?
A .pkl file contains a Python object serialized using the pickle module from the Python standard library. Pickling converts nearly any Python data structure - dictionaries, lists, class instances, NumPy arrays, trained machine learning models - into a byte stream that can be saved to disk and later restored with pickle.load().
The format uses a stack-based Pickle Virtual Machine (PVM): a stream of single-byte opcodes that, when executed, reconstruct the original object. Protocol versions range from Protocol 0 (text-based opcodes, Python 1.2) through Protocol 5 (Python 3.8+, PEP 574, supporting out-of-band buffers for large NumPy arrays). Protocol 4 (magic bytes 80 04 95) is the default in Python 3.8-3.11. There is no fixed schema; the byte stream structure is entirely determined by the object being serialized.
The dominant modern use is saving trained ML models from scikit-learn, PyTorch (torch.save wraps pickle internally), and XGBoost, and caching expensive computed results. The joblib library (which also uses pickle) is preferred for large NumPy arrays due to memory-mapping support.
Security warning: loading a .pkl file from an untrusted source can execute arbitrary Python code. Safer alternatives include .json for simple data, HDF5 or Parquet for tabular data, and ONNX or safetensors for ML models. The .pkl and .pickle extensions are fully interchangeable.
Security & safety
RISK: HIGHPython Pickle can execute arbitrary code during loading (via __reduce__ / REDUCE opcode). A malicious .pkl file is a code execution attack vector - treat like an executable. Only load .pkl files from sources you trust completely. For ML model sharing, prefer safetensors (HuggingFace) or ONNX format which cannot execute code on load. The pickle docs explicitly warn: "The pickle module is not secure."
Format details
in a nutshell- Microsoft Exchange Migration Wizard Packing List - Legacy Microsoft Exchange migration tool used .pkl for packing lists; completely unrelated to Python pickle.
Programs that open PKL files
Technical details
deep spec| Encoding | Binary opcode stream for the Pickle Virtual Machine (PVM) |
| Protocol 4 magic bytes | 80 04 95 at offset 0 (Python 3.4+; default in Python 3.8-3.11) |
| Protocol 5 magic bytes | 80 05 at offset 0 (Python 3.8+, PEP 574, out-of-band buffer support for NumPy) |
| Protocol 2 magic bytes | 80 02 at offset 0 (Python 2.3+, new-style class support, PEP 307) |
| Protocol range | Protocol 0 (text opcodes, 1995) through Protocol 5 (Python 3.8+, 2019) |
| Data structure | Flat opcode stream with operand stack and memo table; STOP opcode (0x2E) marks end of stream |
| Schema | No fixed schema; structure is determined entirely by the Python object being serialized |
| MIME type | application/octet-stream (no registered MIME type) |
| Typical file size | 1 KB - several GB (small dicts to large ML model weight tensors) |
| Security risk | Arbitrary Python code execution possible on pickle.load() from untrusted sources |
| Cross-language portability | Python-only; no other language can natively read or write this format |
| Primary modern use | Saving scikit-learn models, PyTorch weights (torch.save), XGBoost models, cached computations |
| Interchangeable extension | .pickle is identical in format and fully interchangeable with .pkl |
| Related library | joblib wraps pickle with memory-mapping optimizations suited for large NumPy arrays |
| Released | 1995 (Python 1.2, original pickle module) |
| Latest version | Protocol 5 (Python 3.8+, PEP 574, 2019) |
| Specification | docs.python.org |