pickle
noun
say it: “PIK-ul” /ˈpɪkəl/
Python's built-in module for saving objects as bytes and loading them back; files should only be loaded from trusted sources.
What is Python's pickle module?
pickle is Python's built-in module for turning almost any object, a trained model included, into bytes you can save, and back into the object. Loading a pickle can run code hidden in it, so only load files you made or trust.
import pickle
prices = {"latte": 4.5, "mocha": 5.0}
data = pickle.dumps(prices) # to bytes
print(pickle.loads(data)) # {'latte': 4.5, 'mocha': 5.0}
In a sentence
- “Never load a pickle file someone emailed you: loading it can run code.”
- “She saved the model with pickle and loaded it in the API.”
Level: Journeyman · More Python terms at this level
Updated