{"id":1604,"date":"2024-01-01T17:25:45","date_gmt":"2024-01-01T11:55:45","guid":{"rendered":"https:\/\/geekpython.in\/?p=1604"},"modified":"2024-03-01T17:03:42","modified_gmt":"2024-03-01T11:33:42","slug":"pickle-module-in-python","status":"publish","type":"post","link":"https:\/\/geekpython.in\/pickle-module-in-python","title":{"rendered":"Pickle Python Object Using the pickle Module"},"content":{"rendered":"\n<p>Sometimes you need to send complex data over the network, save the state of the data into a file to keep in the local disk or database, or cache the data of expensive operation, in that case, you need to serialize the data.<\/p>\n\n\n\n<p>Python has a standard library called <code>pickle<\/code> that helps you perform the serialization and de-serialization process on the Python objects.<\/p>\n\n\n\n<p>In this article, you&#8217;ll learn about data serialization and deserialization, the pickle module&#8217;s key features and how to serialize and deserialize objects, the types of objects that can and cannot be pickled, and how to modify the pickling behavior in a class.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Object Serialization<\/h2>\n\n\n\n<p>Well, serialization refers to the process of converting the data into a format that can be easily stored, transmitted, or reconstructed for later use.<\/p>\n\n\n\n<p>Pickling is the name given to the serialization process in Python, where Python objects are converted into a byte stream. Unpickling, also known as deserializing, is the inverse operation in which byte data is converted back to its original state, reconstructing the Python object hierarchy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The pickle Module<\/h2>\n\n\n\n<p>Pickling and unpickling are Python-specific operations that require the use of the <code>pickle<\/code> module.<\/p>\n\n\n\n<p>The <code>pickle<\/code> module includes four functions for performing the pickling and unpickling processes on objects:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>pickle.dump(obj, file)<\/code><\/td><td><code>pickle.load(file)<\/code><\/td><\/tr><tr><td><code>pickle.dumps(obj)<\/code><\/td><td><code>pickle.loads(data)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The <code>pickle.dump()<\/code> function is used to write the serialized byte representation of the object into a specified file or file-like object.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>obj<\/code>: The object to be serialized.<\/li>\n\n\n\n<li><code>file<\/code>: The file or file-like object in which the serialized byte representation of the object will be written.<\/li>\n<\/ul>\n\n\n\n<p>The <code>pickle.dumps()<\/code> function returns the serialized byte representation of the object.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>obj<\/code>: The object to be serialized.<\/li>\n<\/ul>\n\n\n\n<p>The <code>pickle.load()<\/code> function reads the serialized object from the specified file or file-like object and returns the reconstructed object.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>file<\/code>: The file or file-like object from which the serialized data is read.<\/li>\n<\/ul>\n\n\n\n<p>The <code>pickle.loads()<\/code> function returns the reconstructed object from the serialized bytes object.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>obj<\/code>: serialized bytes object to reconstruct.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Pickle and Unpickle Data<\/h2>\n\n\n\n<p>Consider the following scenario: pickling the data and saving it to a file, then unpickling the serialized object from that file to reassemble it in its original form.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import pickle\n\n# Sample data\nmy_data = {\n    \"lib\": \"pickle\",\n    \"build\": 4.33,\n    \"version\": 2.1,\n    \"status\": \"Active\"\n}\n\n# Serializing\nwith open(\"lib_info.pickle\", \"wb\") as file:\n    pickle.dump(my_data, file)\n\n# De-serializing\nwith open(\"lib_info.pickle\", \"rb\") as file:\n    unpickled_data = pickle.load(file)\n\nprint(f\"Unpickled Data: {unpickled_data}\")<\/pre><\/div>\n\n\n\n<p>The above code serializes the <code>my_data<\/code> dictionary and the serialized data is written to a file called <code>lib_info.pickle<\/code> in binary mode (<code>wb<\/code>).<\/p>\n\n\n\n<p>The serialized data is then deserialized from the <code>lib_info.pickle<\/code> using the <code>pickle.load()<\/code> function.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Unpickled Data: {'lib': 'pickle', 'build': 4.33, 'version': 2.1, 'status': 'Active'}<\/pre><\/div>\n\n\n\n<p>Take a look at another example in which you have a class that contains multiple operations.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import pickle\n\nclass SampleOperation:\n    square = 5 ** 2\n    addition = 5 + 7\n    subtraction = 5 - 7\n    division = 14 \/ 2\n\n# Object created\nmy_obj = SampleOperation()\n\n# Serializing\npickled_data = pickle.dumps(my_obj)\nprint(f\"Pickled Data: {pickled_data}\")\n\n# De-serializing\nunpickled_data = pickle.loads(pickled_data)\nprint(f\"Unpickled Data (Division): {unpickled_data.division}\")\nprint(f\"Unpickled Data (Square): {unpickled_data.square}\")\nprint(f\"Unpickled Data (Addition): {unpickled_data.addition}\")\nprint(f\"Unpickled Data (Subtraction): {unpickled_data.subtraction}\")<\/pre><\/div>\n\n\n\n<p>In the above code, an object of the <code>SampleOperation<\/code> class is created and stored in the <code>my_obj<\/code> variable.<\/p>\n\n\n\n<p>The object <code>my_obj<\/code> is serialized using the <code>pickle.dumps()<\/code> function and the serialized data is stored in the <code>pickled_data<\/code> variable.<\/p>\n\n\n\n<p>Then, the serialized data (<code>pickled_data<\/code>) is deserialized using the <code>pickle.loads()<\/code> function and the attributes of the unpickled object are printed.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Pickled Data: b'\\x80\\x04\\x95#\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x8c\\x08__main__\\x94\\x8c\\x0fSampleOperation\\x94\\x93\\x94)\\x81\\x94.'\nUnpickled Data (Division): 7.0\nUnpickled Data (Square): 25\nUnpickled Data (Addition): 12\nUnpickled Data (Subtraction): -2<\/pre><\/div>\n\n\n\n<p>This demonstrates that the deserialization process successfully reconstructed the object.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Can be Pickled and Unpickled?<\/h2>\n\n\n\n<p>The <code>pickle<\/code> module can pickle a variety of objects, including strings, integers, floats, tuples, named functions, classes, and others.<\/p>\n\n\n\n<p>However, not all types of objects are picklable. Certain types of objects, for example, file handles, sockets, database connections, and custom classes that lack necessary methods (such as <code>__getstate__<\/code> and <code>__setstate__<\/code>), may not be picklable.<\/p>\n\n\n\n<p>Here&#8217;s an example of attempting to pickle a database connection.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import pickle\nimport sqlite3\n\nconn = sqlite3.connect(\":memory:\")\n# Pickling db connection object\npickle.dumps(conn)<\/pre><\/div>\n\n\n\n<p>When you run this code, you will receive a <code>TypeError<\/code> stating that the connection object cannot be pickled.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">TypeError: cannot pickle 'sqlite3.Connection' object<\/pre><\/div>\n\n\n\n<p>Similarly, functions that are not defined with the <code>def<\/code> keyword, such as the <code>lambda<\/code> function, cannot be pickled using the <code>pickle<\/code> module.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import pickle\n\nlambda_obj = lambda x: x ** 2\npickle.dumps(lambda_obj)<\/pre><\/div>\n\n\n\n<p>The above code is attempting to pickle the <code>lambda<\/code> function object, but it will return an error.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Traceback (most recent call last):\n  ...\n    pickle.dumps(lambda_obj)\n_pickle.PicklingError: Can't pickle &lt;function &lt;lambda&gt; at 0x000001EB55373E20&gt;: attribute lookup &lt;lambda&gt; on __main__ failed<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Modify the Pickling Behaviour of the Class<\/h2>\n\n\n\n<p>Let&#8217;s say you have a class that contains different attributes and some of them are unpicklable. In that case, you can override the <code>__getstate__<\/code> method of the class to choose what you want to pickle during the pickling process.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import pickle\n\nclass SampleTask:\n    def __init__(self):\n        self.first = 2**17\n        self.second = \"This is a string\".upper()\n        self.third = lambda x: x**x\n\nobj = SampleTask()\npickle_instance = pickle.dumps(obj)\nunpickle = pickle.loads(pickle_instance)\nprint(unpickle.__dict__)<\/pre><\/div>\n\n\n\n<p>If you directly run the above code, the result will be an error due to the <code>lambda<\/code> function defined within the class which is unpicklable.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Traceback (most recent call last):\n  ....\n    pickle_instance = pickle.dumps(obj)\nAttributeError: Can't pickle local object 'SampleTask.__init__.&lt;locals&gt;.&lt;lambda&gt;'<\/pre><\/div>\n\n\n\n<p>To tackle this kind of situation, you can influence the pickling process of the class instance using the <code>__getstate__<\/code> method. You can include what to pickle by overriding the <code>__getstate__<\/code> method.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python mark:11 decode:true \">import pickle\n\nclass SampleTask:\n    def __init__(self):\n        self.first = 2**17\n        self.second = \"This is a string\".upper()\n        self.third = lambda x: x**x\n\n    def __getstate__(self):\n        state = self.__dict__.copy()\n        del state['third']\n        return state\n\nobj = SampleTask()\npickle_instance = pickle.dumps(obj)\nunpickle = pickle.loads(pickle_instance)\nprint(unpickle.__dict__)<\/pre><\/div>\n\n\n\n<p>In the above example, the <code>__getstate__<\/code> method is defined, and within this method, a copy of the attributes is made. To exclude the <code>lambda<\/code> function from the pickling process, the attribute named <code>third<\/code> is removed and then the attributes are returned.<\/p>\n\n\n\n<p>When you run the above example, you will get the dictionary containing the results of the attributes.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">{'first': 131072, 'second': 'THIS IS A STRING'}<\/pre><\/div>\n\n\n\n<p>Now if you want the excluded <code>lambda<\/code> expression to appear in the unpickled dictionary above, you can use the <code>__setstate__<\/code> method to restore the state of the class&#8217;s object.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python mark:16 decode:true \">import pickle\n\nclass SampleTask:\n    def __init__(self):\n        self.first = 2**17\n        self.second = \"This is a string\".upper()\n        self.third = lambda x: x**x\n\n    def __getstate__(self):\n        state = self.__dict__.copy()\n        del state['third']\n        return state\n\n    def __setstate__(self, state):\n        self.__dict__.update(state)\n        self.third = lambda x: x**x\n\nobj = SampleTask()\npickle_instance = pickle.dumps(obj)\nunpickle = pickle.loads(pickle_instance)\nprint(unpickle.__dict__)<\/pre><\/div>\n\n\n\n<p>In the above code, the <code>__setstate__<\/code> method restores the state of the object. During unpickling, the <code>__setstate__<\/code> method is called to restore the state of the object.<\/p>\n\n\n\n<p>When you run the above code, you will see the dictionary having the <code>lambda<\/code> function object.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">{'first': 131072, 'second': 'THIS IS A STRING', 'third': &lt;function SampleTask.__setstate__.&lt;locals&gt;.&lt;lambda&gt; at 0x000001C54EEB67A0&gt;}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Customizing Pickling: Modifying Class Behavior for Database Connections<\/strong><\/h2>\n\n\n\n<p>As you know, a variety of objects are unpicklable. Here&#8217;s an example that shows how you can pickle the database connection object by modifying the pickling behavior of the class.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" title=\"pickling_db_obj.py\"># pickling_db_obj.py\nimport pickle\nimport sqlite3\n\nclass DBConnection:\n    def __init__(self, db_name):\n        self.db_name = db_name\n        self.connection = sqlite3.connect(db_name)\n        self.cur = self.connection.cursor()\n    \n    # Method for creating db table\n    def create_table(self):\n        self.connection.execute(\"CREATE TABLE IF NOT EXISTS users (name TEXT)\")\n        return self.connection\n\n    # Method for inserting data into db table\n    def create_entry(self):\n        self.connection.execute(\"INSERT INTO users (name) VALUES ('Sachin')\")\n        res = self.connection.execute(\"SELECT * FROM users\")\n        result = res.fetchall()\n        print(result)\n        return self.connection\n\n    # Method for closing db connection\n    def close_db_connection(self):\n        self.cur.close()\n        self.connection.close()<\/pre><\/div>\n\n\n\n<p>The above code defined a class <code>DBConnection<\/code>, and the SQLite database connection is initialized within this class.<\/p>\n\n\n\n<p>In addition, three new methods are added: <code>create_table<\/code> (for creating a database table), <code>create_entry<\/code> (for inserting and retrieving data from the table), and <code>close_db_connection<\/code> (for closing the database connection).<\/p>\n\n\n\n<p>Now exclude the database connection from the pickling process using the <code>__getstate__<\/code> method.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \" title=\"pickling_db_obj.py\"># pickling_db_obj.py\n...\n\n    def __getstate__(self):\n        state = self.__dict__.copy()\n        # Exclude the connection and cursor from pickling\n        del state['connection']\n        del state['cur']\n        return state\n\ndb_conn = DBConnection(\":memory:\")\npickle_db_conn = pickle.dumps(db_conn)\nunpickle_db_conn = pickle.loads(pickle_db_conn)\nprint(unpickle_db_conn.__dict__)<\/pre><\/div>\n\n\n\n<p>The <code>__getstate__<\/code> method creates a copy of the object&#8217;s dictionary, then removes the connection (<code>state['connection']<\/code>) and cursor (<code>state['cur']<\/code>) and returns the dictionary (<code>state<\/code>).<\/p>\n\n\n\n<p>The <code>DBConnection<\/code> class instance is created and passed the database name (<code>\":memory:\"<\/code>) that will be created in memory.<\/p>\n\n\n\n<p>The database connection object is then pickled, which is then unpickled and printed.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">{'db_name': ':memory:'}<\/pre><\/div>\n\n\n\n<p>As you can see, the dictionary of the object only contains the database name. The connection and cursor objects have been removed.<\/p>\n\n\n\n<p>The <code>__setstate__<\/code> method is now required to restore the object&#8217;s original state during unpickling, in which the database connection will be reestablished.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python mark:17-19 decode:true \" title=\"pickling_db_obj.py\"># pickling_db_obj.py\n...\n\n    ...\n\n    # Restoring the original state of the object\n    def __setstate__(self, state):\n        self.__dict__.update(state)\n        self.connection = sqlite3.connect(self.db_name)\n        self.cur = self.connection.cursor()\n\n\ndb_conn = DBConnection(\":memory:\")\npickle_db_conn = pickle.dumps(db_conn)\nunpickle_db_conn = pickle.loads(pickle_db_conn)\n\nunpickle_db_conn.create_table()\nunpickle_db_conn.create_entry()\nunpickle_db_conn.close_db_connection()\n\nprint(unpickle_db_conn.__dict__)<\/pre><\/div>\n\n\n\n<p>Within the <code>__setstate__<\/code> method, the <code>state<\/code> dictionary is updated and the new database connection and the cursor are created.<\/p>\n\n\n\n<p>To check if the pickling process works, the <code>create_table<\/code>, <code>create_entry<\/code>, and <code>close_db_connection<\/code> methods are called on the unpickled class instance (<code>unpickle_db_conn<\/code>).<\/p>\n\n\n\n<p>When you run the whole script, you will obtain the following output.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">[('Sachin',)]\n{'db_name': ':memory:', 'connection': &lt;sqlite3.Connection object at 0x00000240D6F12A40&gt;, 'cur': &lt;sqlite3.Cursor object at 0x00000240D78044C0&gt;}<\/pre><\/div>\n\n\n\n<p>As you can see, everything went well, and the object&#8217;s dictionary now has both a connection and a cursor object along with the database name, demonstrating the successful unpickling of the database connection.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Keep in mind that if the <code>__getstate__<\/code> method returns the false value, the <code>__setstate__<\/code> method will not be called upon unpickling. <a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/pickle.html#object.__setstate__\">Source<\/a><\/p>\n<\/blockquote>\n\n\n\n<p>While the ability to customize the <code>__setstate__<\/code> method during unpickling provides flexibility, it also comes with security considerations. Arbitrary code can be executed during unpickling, which can be a security risk if the pickled data comes from untrusted or malicious sources.<\/p>\n\n\n\n<p>So, what can you do to reduce the security risk? You can&#8217;t do much, but you can make sure that data from untrustworthy sources isn&#8217;t unpickled. Validate the authenticity of the pickled data during unpickling by using cryptographic signatures to ensure that it has not been tampered with, and if possible, sanitize the pickled data by checking for malicious content.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The pickle module lets you serialize and deserialize the data and now you know how to do it using the pickle module. You can now convert the object data into bytes that can be transmitted over a network or saved into disk for the future.<\/p>\n\n\n\n<p>In this article, you&#8217;ve learned:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What are object serialization and deserialization<\/li>\n\n\n\n<li>How to pickle and unpickle data using the pickle module<\/li>\n\n\n\n<li>What type of object can and can&#8217;t be pickled<\/li>\n\n\n\n<li>How to modify the pickling behavior of the class<\/li>\n\n\n\n<li>How to modify the class behavior for database connection<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83c\udfc6<strong>Other articles you might be interested in if you liked this one<\/strong><\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/hash-passwords-using-bcrypt-in-python\">Hash passwords using the bcrypt library in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/understanding-pytest-to-test-python-code\">How to use pytest to test your Python code<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/build-websocket-server-and-client-using-python\">Create a WebSocket server and client in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/threading-module-to-create-threads-in-python\">Create multi-threaded Python programs using a threading module<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/create-and-integrate-mysql-database-with-flask-app\">Create and integrate MySQL database with Flask app using Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/render-images-from-flask\">Upload and display images on the frontend using Flask<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>That&#8217;s all for now<\/strong><\/p>\n\n\n\n<p><strong>Keep Coding\u270c\u270c<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need to send complex data over the network, save the state of the data into a file to keep in the local disk or database, or cache the data of expensive operation, in that case, you need to serialize the data. Python has a standard library called pickle that helps you perform the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1606,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[2],"tags":[31],"class_list":["post-1604","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python3","entry","has-media"],"_links":{"self":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/comments?post=1604"}],"version-history":[{"count":4,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1604\/revisions"}],"predecessor-version":[{"id":1609,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1604\/revisions\/1609"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media\/1606"}],"wp:attachment":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media?parent=1604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/categories?post=1604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/tags?post=1604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}