Serializing Objects With the Python pickle Module (Summary)
You now know how to use the Python pickle
module to convert an object hierarchy to a stream of bytes that can be saved to a disk or transmitted over a network. You also know that the deserialization process in Python must be used with care since unpickling something that comes from an untrusted source can be extremely dangerous.
In this course, you’ve learned:
- What it means to serialize and deserialize an object
- Which modules you can use to serialize objects in Python
- Which kinds of objects can be serialized with the Python
pickle
module - How to use the Python
pickle
module to serialize object hierarchies - What the risks are of unpickling from an untrusted source
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
All right! So in this course, you learned all about using the Python pickle
module to serialize objects. You learned what serialization is and some of the different methods of doing serialization in Python,
00:14
how to use the pickle
module to serialize objects, some of the different types of pickle
protocols and how to work with them across different versions of Python, some unpickleable data types and using the dill
module to extend upon what pickle
can do, defining the .__getstate__()
and .__setstate__()
dunder methods to control how objects are serialized, compressing your pickled data, and then you went through an example of a security concern when using pickle
.
00:45
pickle
is a very powerful tool for storing and sending the state of objects in your Python scripts, and now is a great time to see where you can use this tool in some of your projects. Thanks for watching.
Become a Member to join the conversation.
Jon Nyquist on Dec. 24, 2020
I read an article on Medium suggesting breaking long Jupyter notebooks into smaller concerns with pickle to pass pandas dataframes between the notebooks.
df.to_pickle(PROCESSED_FILE)
Seems like an interesting idea.