

{"id":11819,"date":"2018-03-27T05:38:44","date_gmt":"2018-03-27T00:08:44","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=11819"},"modified":"2026-04-25T11:08:24","modified_gmt":"2026-04-25T05:38:24","slug":"python-pickle","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-pickle\/","title":{"rendered":"Python Pickle | What is Serialization in Python with Example"},"content":{"rendered":"<p>In this Python Pickle tutorial, we will study what a Pickle is in Python and how Python Serialization deals with the \u2018pickle\u2019 module of Python for serialization.<\/p>\n<p>At last, we will discuss some Python Pickle Examples. So, let&#8217;s start the Python Pickle Tutorial.<\/p>\n<h3>What is Serialization in Python?<\/h3>\n<p>In Python, when we want to serialize and deserialize a Python object, we use functions and methods from the Python pickle module. Pickling turns objects into byte streams via pickle.dumps(); load them back with pickle.loads().<\/p>\n<p>We also call this \u2018serialization\u2019, \u2018marshalling\u2019, or \u2018flattening\u2019. Unpickling is its inverse, ie., converting a byte stream from a binary file or bytes-like object into an object.<\/p>\n<p><strong>Advantages of Serialization in Python:<\/strong><\/p>\n<ul>\n<li><strong>Saving progress:<\/strong> You can save the program wherever you have left it and save it in a file, and load it later from where you left off.<\/li>\n<li><strong>Data sending:<\/strong> Python lets you send the data to other systems and websites easily.<\/li>\n<li><strong>Sharing:<\/strong> By using formats like JSON, the data can be shared with programs written in other languages, like JavaScript or Java.<\/li>\n<\/ul>\n<h3>Comparing Python Pickle to Other Python Modules<\/h3>\n<h4>1. Comparing Python pickle to marshal<\/h4>\n<p>\u2018marshal\u2019 is a more primitive module for serialization in Python, and its purpose is to support .pyc files. However, we prefer Python pickle. The two differ in the following ways:<\/p>\n<ol>\n<li>Python pickle tracks the objects it has serialized. Because of this, it doesn\u2019t have to serialize the same objects again when it references them again. This is unlike Marshal.<\/li>\n<li>Marshal cannot serialize user-defined classes and their instances. If the class definition is importable and in the same module as when we stored the object, pickle can save and restore class instances.<\/li>\n<li>The serialization format for pickle in Python is backwards-compatible. This isn\u2019t the same as Marshal.<\/li>\n<\/ol>\n<h4>2. Comparing Python pickle to JSON<\/h4>\n<p>JSON is a standard library module for serialization and deserialization with Python.<\/p>\n<ol>\n<li>Where Python pickle has a binary serialization format, JSON has a text serialization format.<\/li>\n<li>Python pickle isn\u2019t human-readable, but marshal isn\u2019t.<\/li>\n<li>pickle is Python-specific, but JSON is interoperable.<\/li>\n<li>pickle can represent a very large number of Python types. However, JSON can only represent a subset of Python\u2019s built-in types.<\/li>\n<\/ol>\n<h3>Python Pickle Supports Data Stream Format<\/h3>\n<p>Python pickle uses a Python-specific data format. So, external standards like JSON or XDR impose no restrictions. But this makes it impossible for non-Python programs to reconstruct pickled Python objects.<\/p>\n<p>As we said above, Python pickle uses a data format with a relatively compact binary representation. We can efficiently compress it.<\/p>\n<p>Complementary to Python pickle is the module \u2018pickletools\u2019 for analyzing data streams that it generates.<\/p>\n<p><strong>We have five different protocols for pickling:<\/strong><\/p>\n<p><strong>1. Protocol version 0:<\/strong>\u00a0Original, human-readable protocol; backwards-compatible with earlier versions of Python.<\/p>\n<p><strong>2. Protocol version 1:<\/strong>\u00a0Old, binary format; compatible with earlier versions of Python.<\/p>\n<p><strong>3. Protocol version 2:<\/strong>\u00a0Added in Python 2.3; provides more efficient pickling of new-style classes.<\/p>\n<p><strong>4. Protocol version 3:<\/strong>\u00a0Introduced in Python 3.0; default; supports bytes objects; cannot be unpickled by Python 2.x. It is recommended when we need compatibility with other Python 3 versions.<\/p>\n<p><strong>5. Protocol version 4:<\/strong>\u00a0Introduced in Python 3.4; supports very large objects, more kinds of objects, and certain data format optimizations.<\/p>\n<h3>Pickle Module Interface in Python<\/h3>\n<p>To serialize and deserialize, we use functions dumps() and loads(), respectively. Alternatively, we can create our own Pickler and Unpickler objects for more control over this.<\/p>\n<p>Python pickle has two constants:<\/p>\n<h4>1. HIGHEST_PROTOCOL in Python<\/h4>\n<p>This is an integer, and it holds the highest protocol version that is available. We can pass this as a <i>protocol<\/i> value to dump() and dumps(), and to the Pickler constructor.<\/p>\n<h4>2. DEFAULT_PROTOCOL in Python<\/h4>\n<p>Also an integer, this holds the default protocol version for pickling. The default is currently Protocol 3.<\/p>\n<p>It also has the following functions:<\/p>\n<p><strong>a. dump(obj, file, protocol=None, *, fix_imports=True)<\/strong><\/p>\n<p>This writes a pickled representation of object <i>obj<\/i> to <i>file<\/i>, an open file object. Consider this equivalent to Pickler(file, protocol).dump(obj)<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; x=7\r\n&gt;&gt;&gt; import os\r\n&gt;&gt;&gt; os.chdir('C:\\\\Users\\\\lifei\\\\Desktop')\r\n&gt;&gt;&gt; import pickle\r\n&gt;&gt;&gt; f=open('abcde.txt','r+b')  \/\/opened it in binary mode to pickle\r\n&gt;&gt;&gt; pickle.dump(x,f)<\/pre>\n<p>When we checked the file abcde.txt, we found this:<br \/>\n\u20acK. \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u20acK.\u20acK.<br \/>\n<i><\/i><i>file<\/i>, here, must have a write() method accepting a single byte argument.<\/p>\n<p>So, it can be a file you opened in binary mode, an io.BytesIO instance, or a custom object meeting this interface. P<i>rotocol<\/i> lets us choose which protocol to use.<\/p>\n<p>When <i>fix_imports<\/i> is true, and we use a protocol less than 3, pickle maps new Python 3 names to old module names in Python 2. This lets Python 2 read the pickle data stream.<\/p>\n<p><strong>b. dumps(obj, protocol=None, *, fix_imports=True)<\/strong><\/p>\n<p>This returns the pickled representation of <i>obj<\/i> as a bytes object. This does not write it to a file.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; pickle.dumps(x)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>b&#8217;\\x80\\x03K\\x07.&#8217;<\/p>\n<\/div>\n<p><strong>c. load(file, *, fix_imports=True, encoding=&#8221;ASCII&#8221;, errors=&#8221;strict&#8221;)<\/strong><\/p>\n<p>load() takes in a <i>file<\/i>, an open file object, reads a pickled representation from it, and returns the reconstructed object hierarchy. Consider this equivalent to Unpickler(file).load()<\/p>\n<p><i>file<\/i> can be a file object opened in the binary reading mode, an io.BytesIO object, or an object that meets its interface. This is because it must have two methods- \u00a0read(), which takes one integer argument, and readline(), which takes no arguments.<\/p>\n<p>Both of these methods must return bytes.<\/p>\n<p>fix_imports, encoding, and errors help control compatibility support for pickle streams by Python 2. When fix_imports is true, pickle maps old Python 2 names to new Python 3 names.<\/p>\n<p>The other two guide pickle with decoding 8-bit string instances pickled by Python 2. The default encoding is \u2018ASCII\u2019, and the default value for errors is \u2018strict\u2019.<\/p>\n<p>To read such 8-bit string instances as byte objects, we can set the encoding to \u2018bytes\u2019.<\/p>\n<p>Let\u2019s try doing this.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; pickle.load(f)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#63&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>pickle.load(f)<\/p>\n<p>EOFError: Ran out of input<\/p>\n<\/div>\n<p>Uh-oh. Let\u2019s get to the beginning of the file.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; f.seek(0)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>0<\/p>\n<\/div>\n<p>Now, we can successfully load it.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; pickle.load(f)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<\/div>\n<p><strong>d. loads(bytes_object, *, fix_imports=True, encoding=&#8221;ASCII&#8221;, errors=&#8221;strict&#8221;)<\/strong><\/p>\n<p>This function takes in a bytes object, reads a pickled object hierarchy, and returns the reconstructed object hierarchy.<\/p>\n<p>fix_imports, encoding, and errors help control compatibility support for pickle streams that Python 2 generates.<\/p>\n<p>When it is true, pickle maps old Python 2 names to new Python 3 names. encoding guides pickle with decoding 8-bit string instances pickled by Python 2.<\/p>\n<p>The default for encoding is \u2018ASCII\u2019, and that for errors is \u2018strict\u2019. To read such 8-byte instances as byte objects, we can set the encoding to \u2018bytes\u2019.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; f.seek(0)<\/pre>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; pickle.loads(f.read())<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<\/div>\n<h3>Python Pickle Exceptions<\/h3>\n<p>The Python pickle module also defines three kinds of exceptions:<\/p>\n<h4>1. PickleError in Python<\/h4>\n<p>This is the common parent class for all other pickling exceptions. It, in turn, inherits from Exception.<\/p>\n<h4>2. PicklingError in Python<\/h4>\n<p>When the Pickler encounters an unpicklable object, it raises a PicklingError. This class inherits from PickleError.<\/p>\n<h4>3. UnpicklingError in Python<\/h4>\n<p>When Python pickle cannot unpickle an object due to data corruption or a security violation, it raises an UnpicklingError. This inherits from PickleError.<\/p>\n<p>Some other exceptions we observe when pickling, as we did above, include:<br \/>\nEOFError<br \/>\nTypeError<br \/>\nValueError<br \/>\nAttributeError<br \/>\nImportError<br \/>\nIndexError<\/p>\n<h3>Imported Classes in Python Pickle<\/h3>\n<p>Python pickle imports two classes- Pickler and Unpickler:<\/p>\n<h4>1. Pickler(file, protocol=None, *, fix_imports=True) in Python<\/h4>\n<p>Pickler takes in a binary file and writes a pickle data stream.<br \/>\n<i><\/i><\/p>\n<p><i>file<\/i> must have a write() method accepting a single byte argument. This can be a file object for a file opened for writing in binary mode, an io.BytesIO instance, or a custom object meeting this interface.<br \/>\n<i><\/i><\/p>\n<p><i>protocol<\/i> is an integer, and informs the pickler about which protocol to use (0 to HIGHEST_PROTOCOL). Otherwise, it uses DEFAULT_PROTOCOL. On providing a negative number, it selects HIGHEST_PROTOCOL.<\/p>\n<p>When <i>fix_imports<\/i> is true, and the protocol version is less than 3, pickle maps new Python 3 names to old Python 2 names. This makes the Python data stream readable by Python 2.<\/p>\n<p>Python Pickler has the following members:<\/p>\n<p><strong>a. dump(obj)<\/strong><\/p>\n<p>This takes in <i>obj<\/i> and writes a pickled representation of it to the open file object specified in the constructor of Pickler.<\/p>\n<p><strong>b. persistent_id(obj)<\/strong><\/p>\n<p>By default, it does nothing. It only exists to let subclasses override it. If it returns none, pickle pickles <i>obj<\/i> as usual.<\/p>\n<p>Otherwise, Pickler emits the returned value as a persistent ID for <i>obj<\/i>. Unpickler.persistent_load() defines this context.<\/p>\n<p><strong>c. dispatch_table<\/strong><\/p>\n<p>For an object of Pickler, a dispatch table is a registry holding reduction functions that we can declare with copyreg.pickle(). This mapping has classes as its keys, and reduction functions as its values.<\/p>\n<p>A reduction function takes one argument of the class, and conforms to this interface as a __reduce__() method.<\/p>\n<p>But pickler objects don\u2019t have dispatch_tables by default. Instead, it makes use of the global dispatch table that the copyreg module manages.<\/p>\n<p>To customize pickling for an object of a specific object of Pickler, we can set dispatch_table to a dict-like object.<\/p>\n<p>Or, if one of the subclasses of Pickler has dispatch_table, then this serves as the default dispatch table for instances of that class.<\/p>\n<p><strong>d. fast<\/strong><\/p>\n<p>Although this is deprecated(no longer advised), it enables fast mode when set to true. This mode disables memo, thereby speeding pickling as it doesn\u2019t generate extra PUT opcodes.<\/p>\n<p>However, do not use it with self-referential objects, as it can set Pickler off into infinite recursion.<\/p>\n<p>For more compact pickles, we can use pickletools.optimize().<\/p>\n<h4>2. Unpickler(file, *, fix_imports=True, encoding=&#8221;ASCII&#8221;, errors=&#8221;strict&#8221;) in Python<\/h4>\n<p>The Unpickler takes in a binary file and reads a pickle data stream.<br \/>\n<i><\/i><\/p>\n<p><i>file<\/i> must have the methods read()- that takes an integer argument, and readline()- that needs no arguments. Both of these methods must return bytes.<\/p>\n<p>This can be a file object opened for reading in binary mode, an io.BytesIO object, or a custom object meeting this interface.<\/p>\n<p>pickle automatically detects the version of protocol used; we don\u2019t need an argument for that.<br \/>\n<i><\/i><\/p>\n<p><i>fix_imports, encoding, <\/i>and<i> errors <\/i>help control compatibility support for pickle streams generated by Python 2.<\/p>\n<p>When <i>fix_imports<\/i> is true, pickle maps old Python 2 names to new Python 3 names. <i>encoding <\/i>and <i>errors <\/i>guide pickle with decoding 8-bit string instances pickled by Python 2.<\/p>\n<p>The default for <i>encoding <\/i>is \u2018ASCII\u2019, and that for <i>errors<\/i> is \u2018strict\u2019. When we want to read such 8-bit string instances as bytes objects, we can set the <i>encoding<\/i> to \u2018bytes\u2019.<\/p>\n<p>Unpickler has the following members:<\/p>\n<p><strong>1. load()<\/strong><\/p>\n<p>This takes in an open file object, reads a pickled object representation, and returns the reconstructed object hierarchy.<\/p>\n<p><strong>2. persistent_load(pid)<\/strong><\/p>\n<p>By default, this raises an UnpicklingError. When we define it, however, it must return the object about the persistent ID <i>pid<\/i>. If we pass an invalid persistent ID, it raises an UnpicklingError.<\/p>\n<p><strong>3. find_class(module,name)<\/strong><\/p>\n<p>If necessary, it imports the <i>module<\/i>\u00a0and returns the object <i>name<\/i> from it. Here, <i>module<\/i> and <i>name<\/i> are str objects. We can also use find_class() to find functions.<\/p>\n<p>A subclass can override this to control what kind of objects it can take and how we can load them. This alleviates security risks.<\/p>\n<p>Any doubt yet in Python Pickle? Please Comment.<\/p>\n<h3>What Can We Pickle and Unpickle in Python?<\/h3>\n<p>We can pickle the following types:<\/p>\n<ul>\n<li>None, True, and False<\/li>\n<li>integers, floating point numbers, complex numbers<\/li>\n<li>strings, bytes, bytearrays<\/li>\n<li>tuples, lists, sets, and dictionaries holding only picklable objects<\/li>\n<li>functions defined at a module\u2019s top level (using def, not lambda)<\/li>\n<li>built-in functions defined at a module\u2019s top level<\/li>\n<li>classes defined at a module\u2019s top level<\/li>\n<li>instances of such classes whose __dict__ or the result of calling __getstate__() is picklable<\/li>\n<\/ul>\n<p>When we try to pickle an unpicklable object, pickle raises the PicklingError exception. In this process, it is possible that an unspecified number of bytes have already been written to the file.<\/p>\n<p>In trying to pickle a highly recursive data structure, we may exceed the maximum recursion depth. Such a case raises a RecursionError. However, we can raise that limit with sys.setrecursionlimit().<\/p>\n<p>Let\u2019s take a quick look.<\/p>\n<p>We pickle functions by their \u2018fully-qualified\u2019 name references, not by their values. This way, we only pickle the function name and the module it resides in.<\/p>\n<p>We do not pickle the function\u2019s code or attributes. So, we should be able to import the defining module in the unpickling environment.<\/p>\n<p>This module must hold the named object. Otherwise, it raises an exception.<\/p>\n<p>We pickle classes by name reference. This way, the same restrictions apply in the unpickling environment. We do not pickle the class\u2019s code or data. We only pickle instance data.<\/p>\n<p>Such restrictions mandate that we define picklable classes and functions in a module\u2019s top-level.<\/p>\n<p>This was all on Python Pickle and Python Serialization. Hope you now understand Python Serialization.<\/p>\n<h3>Python Interview Questions on Pickle &amp; Serialization<\/h3>\n<p>1. What is a pickle in Python?<\/p>\n<p>2. What is Python pickle used for?<\/p>\n<p>3. How do you pickle data in Python?<\/p>\n<p>4. What is serialization in Python?<\/p>\n<p>5. Is Pickle built in Python?<\/p>\n<h3>Conclusion<\/h3>\n<p>Simply speaking, Python serialization is the act of converting a Python object into a byte stream. In Python, we use the module \u2018pickle\u2019, which has a binary serializable format.<\/p>\n<p>We can also serialize classes and functions. We have also studied in detail Python Pickle and its comparison with other modules.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python Pickle tutorial, we will study what a Pickle is in Python and how Python Serialization deals with the \u2018pickle\u2019 module of Python for serialization. At last, we will discuss some Python&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":31031,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[3975,4088,4542,4712,8356,9000,9479,9485,9486,9487,9489,10758,10831,10832,15162],"class_list":["post-11819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-dispatch_table","tag-dumpobj","tag-fast","tag-find_classmodule","tag-load","tag-name","tag-persistent_loadpid","tag-pickle-dump","tag-pickle-module-interface","tag-pickleerror","tag-picklingerror","tag-python-pickle","tag-python-serialization","tag-python-serialize","tag-unpicklingerror"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Pickle | What is Serialization in Python with Example - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn what is Python Serialization, Pickle vs marshal vs json, Python Pickle Module Interface, Pickler &amp; Unpickler etc.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-pickle\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Pickle | What is Serialization in Python with Example - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn what is Python Serialization, Pickle vs marshal vs json, Python Pickle Module Interface, Pickler &amp; Unpickler etc.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-pickle\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-27T00:08:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-25T05:38:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Serialization-in-Python-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Pickle | What is Serialization in Python with Example - DataFlair","description":"Learn what is Python Serialization, Pickle vs marshal vs json, Python Pickle Module Interface, Pickler & Unpickler etc.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-pickle\/","og_locale":"en_US","og_type":"article","og_title":"Python Pickle | What is Serialization in Python with Example - DataFlair","og_description":"Learn what is Python Serialization, Pickle vs marshal vs json, Python Pickle Module Interface, Pickler & Unpickler etc.","og_url":"https:\/\/data-flair.training\/blogs\/python-pickle\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-03-27T00:08:44+00:00","article_modified_time":"2026-04-25T05:38:24+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Serialization-in-Python-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Pickle | What is Serialization in Python with Example","datePublished":"2018-03-27T00:08:44+00:00","dateModified":"2026-04-25T05:38:24+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/"},"wordCount":2211,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Serialization-in-Python-01-1.jpg","keywords":["dispatch_table","dump(obj)","fast","find_class(module","load()","name)","persistent_load(pid)","pickle dump","Pickle Module Interface","PickleError","PicklingError","Python Pickle","Python Serialization","Python serialize","UnpicklingError"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-pickle\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/","url":"https:\/\/data-flair.training\/blogs\/python-pickle\/","name":"Python Pickle | What is Serialization in Python with Example - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Serialization-in-Python-01-1.jpg","datePublished":"2018-03-27T00:08:44+00:00","dateModified":"2026-04-25T05:38:24+00:00","description":"Learn what is Python Serialization, Pickle vs marshal vs json, Python Pickle Module Interface, Pickler & Unpickler etc.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-pickle\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Serialization-in-Python-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/03\/Serialization-in-Python-01-1.jpg","width":1200,"height":628,"caption":"Python Pickle and Python Serialization"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-pickle\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Pickle | What is Serialization in Python with Example"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=11819"}],"version-history":[{"count":18,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11819\/revisions"}],"predecessor-version":[{"id":147877,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/11819\/revisions\/147877"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/31031"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=11819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=11819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=11819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}