Serializing Objects With the Python pickle Module (Overview)
As a developer, you may sometimes need to send complex object hierarchies over a network or save the internal state of your objects to a disk or database for later use. To accomplish this, you can use a process called serialization, which is fully supported by the standard library thanks to the Python pickle
module.
In this course, you’ll learn:
- 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 when deserializing an object from an untrusted source
00:00
Hello! And welcome to the Real Python course on using the Python pickle
module to serialize objects. In this course, you’re going to learn what serialization is and different types of serialization you can perform in Python, how to use the pickle
module to serialize objects, the different protocols that pickle
has used over its version history, certain types of unpickleable data types and a little bit about the dill
module, the dunder methods .__getstate__()
and .__setstate__()
for Python objects, how to use compression with pickle
, and we’ll discuss some security concerns when using pickle
. By the end of this course, you should feel comfortable using pickle
to persist objects, whether that’s to send them over a network or to save the state of your objects for later use.
Become a Member to join the conversation.