What is the PICKLE file format?
Files with the .pickle extension store Python objects serialized using the pickle module, Python's built-in object serialization library. Both .pickle and .pkl are interchangeable extensions for the same format; .pickle is the longer explicit form while .pkl is the compact three-character variant in use since Python 1.x.
Contents of Python Pickle files
Serialized objects in .pickle files can be of any Python type. .pickle files are used to serialize database objects, cache machine-learning model weights, or store program state between runs. Only .pickle files from trusted sources should be used, as such files can contain malicious software - deserializing an untrusted pickle can execute arbitrary Python code. Pickle objects can be compressed externally using gzip, bz2, or lzma.
How are Python PICKLE files created?
The serialization process is called "pickling" and is done using dump() and dumps() methods. The dump() method is used for serializing an object into a file, while dumps() saves the object as a bytes object. Deserialization - converting the byte stream back to the original object - is done using load() and loads(); this process is referred to as "unpickling".
The pickle protocol version controls the binary format. Protocol 0 is human-readable ASCII; Protocols 1-5 are progressively binary, with Protocol 5 (Python 3.8+) adding out-of-band buffers for efficient handling of large .NPY arrays. In machine-learning workflows, .pickle is widely used to persist scikit-learn models and PyTorch checkpoints, though SafeTensors is gaining adoption as a safer alternative for model weights specifically.
Security & safety
RISK: HIGHCRITICAL WARNING: Pickle files can execute arbitrary Python code when loaded. A malicious .pickle file can delete files, download malware, or take over a system. Never load a pickle file from an untrusted source. In ML/AI workflows, malicious pickles in model repositories (Hugging Face Hub, GitHub) are an active threat vector. Use picklescan to scan files before loading, or switch to SafeTensors format for model weights. CVE-2025-1889: picklescan < 0.0.22 could be bypassed by using non-standard file extensions within archive-based model packages.
Format details
in a nutshellPrograms that open PICKLE files
Technical details
deep spec| File encoding | Binary (protocols 1-5); human-readable ASCII opcodes (protocol 0) |
| Magic bytes | 0x80 followed by protocol version byte; e.g. 0x80 0x05 for protocol 5 (Python 3.8+); protocol 0 has no binary magic |
| Pickle protocols | 0 (ASCII, Python 1.x); 1 (binary, Python 1.x); 2 (new-style classes, Python 2.3+); 3 (bytes, Python 3.0+); 4 (objects >4 GB, Python 3.4+); 5 (out-of-band buffers, Python 3.8+) |
| Default protocol | Protocol 5 is the default in Python 3.8 and later |
| Compression | None built-in; commonly wrapped externally in gzip, bz2, or lzma; joblib adds its own compression layer |
| Encryption | None - no built-in encryption; encrypt at the filesystem or wrapper level if needed |
| Typical file size | Under 1 MB for model configs; 1 MB - several GB for ML model weights and large datasets |
| Security risk | Deserializing untrusted pickle data can execute arbitrary Python code via __reduce__ hooks - never unpickle files from untrusted sources |
| Internal structure | Stream of pickle opcodes encoding Python objects recursively; Protocol 4+ uses frames for chunked streaming; Protocol 5 adds out-of-band buffers for zero-copy of large arrays |
| MIME type | application/octet-stream (formally); application/x-pickle (informal) |
| Cross-platform | Platform-independent; runs on any Python-supported OS (Windows, Linux, macOS) |
| Serialization API | dump() and dumps() for pickling; load() and loads() for unpickling |
| ML/AI usage | Primary serialization format for scikit-learn models and PyTorch checkpoints; SafeTensors is gaining adoption as a safer alternative for model weights |
| Released | 1994 (Python 1.1; pickle module first released) |
| Latest version | Protocol 5 (Python 3.8, 2019); default protocol 5 from Python 3.14 |
| Open standard | Yes · royalty-free |
| Specification | docs.python.org |
PICKLE conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about PICKLE files.