Serializing Objects

Learn about the concepts of serializing and deserializing and explore their implementation using the pickle module.

Serializing and deserializing

We’ve been working with bytes and file paths as foundations that support working with persistent objects. To make an object persistent, we need to create a series of bytes that represent the state of the object, and write those bytes to a file. The missing piece of persistence, then, is this process of encoding objects as a series of bytes. We also want to decode objects and their relationships from a series of bytes. This encoding and decoding is also described as serializing and deserializing.

Press + to interact
A visual representation of serializating and deserializating
A visual representation of serializating and deserializating

When we look at web services, we’ll often see a service described as RESTful. REST stands for REpresentational State Transfer; the server and client will exchange representations of object states. The distinction here can be helpful: the two pieces of software don’t exchange objects. The ...