.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.

How to open 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. For a step-by-step walkthrough, see how to open a .pkl file.

Windows

  • Python (pickle.load)
  • Jupyter

macOS

  • Python (pickle.load)
  • Jupyter

Linux

  • Python (pickle.load)
  • Jupyter

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.

.pkl file signature (magic bytes)

Programs recognise a .pkl file by the bytes at the start of the file, not by its name. These are the signatures for Pickle.

Hex signatureOffsetNote
800protocol 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: