.pkl

What is a .pkl file?

Python Pickle File · Data · Python Software Foundation · 1994

A .pkl file is a Python pickle: a serialized Python object saved to disk, from a trained model to a data structure. It is convenient but dangerous, because loading a pickle can execute arbitrary code.

Category
Data
Type
Binary
Also seen as
.pickle
Is a .pkl file safe to open? Risky. Loading a pickle executes code inside it, so a malicious .pkl can run anything. Never unpickle a file from an untrusted source; prefer safetensors or JSON for sharing.

What is a .pkl file used for?

Pickle turns Python objects into a byte stream and back. Modern pickles (protocol 2 and up) start with the byte 0x80 and a protocol number. It is widely used to save models and datasets in the Python world.

The catch is security: unpickling runs code embedded in the file, so a malicious .pkl can take over your machine. This is exactly why formats like safetensors were created. Only unpickle files you fully trust.

What opens a .pkl file?

The .pkl format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.

Windows

  • Python (pickle.load)
  • Jupyter

macOS

  • Python (pickle.load)
  • Jupyter

Linux

  • Python (pickle.load)
  • Jupyter

Open a .pkl file step by step

  1. Confirm the file really is a .pkl. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with Python (pickle.load) or Jupyter.
  3. On Mac, use Python (pickle.load) or Jupyter.
  4. On Linux, try Python (pickle.load) or Jupyter.
  5. Still stuck? Convert the .pkl to json, which opens more widely.

Why can't I open my .pkl file?

Almost always because no installed app understands Pickle. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .pkl at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

How to convert a .pkl file

You can convert a .pkl file to json, safetensors (for model weights) using a conversion tool or the export menu of an app that opens it.

What is the .pkl file signature (magic bytes)?

A .pkl file starts with the hex bytes 80. Programs identify Pickle by those bytes, not by the filename, so a renamed file still gives itself away.

These are the documented signatures for Pickle.

Documented magic-byte signatures for the .pkl format
Hex signatureOffsetASCIINote
800-protocol 2+ opcode; older protocols are ASCII

See the full magic-numbers reference for every format.

Frequently asked questions

What is a .pkl file?

A .pkl file is a Python pickle: a serialized Python object saved to disk, from a trained model to a data structure. It is convenient but dangerous, because loading a pickle can execute arbitrary code.

How do I open a .pkl file?

In Python, pickle.load() reads it back into an object. Only do this for files you trust, because loading a pickle can run arbitrary code.

Is it safe to open a pickle file?

Not from untrusted sources. Unpickling executes embedded code, a known attack vector. For shared model weights, safetensors is the safe alternative.

What is a .pkl file used for?

Saving Python objects: machine-learning models, preprocessed datasets or any data structure, to reload later in Python.

Related formats

Sources

Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.