Read pickle file

Tags: #python #pickle #file #load #data #io
Author: Kaushal Krishna
Description: This notebook loads a dictionary from pickle object. Loading a dictionary using pickle is a quick and easy process. With just a few lines of code, you can store your dictionary data from a pickle file.
Pickle can cause critical security vulnerabilities in code, you should never unpickle data you don’t trust. If you must accept data from an untrusted client, you should use the safer JSON format. And, if you transfer pickled data between trusted applications but need extra measures to prevent tampering, you should generate an HMAC signature you can verify before unpickling.


Import libraries

import pickle

Setup Variables

  • data: a variable to store unpickled object
  • input_path: pickle file source
# Inputs
input_path = "data.pkl"
# Outputs
data = None


Load dictionary from pickle file

Using the pickle.load() function, the data dictionary can be loaded into from a pickle file.
with open(input_path, "rb") as f:


Display result

print("The unpickled object is : \n", data)