{"id":811,"date":"2022-07-07T22:36:00","date_gmt":"2022-07-07T17:06:00","guid":{"rendered":"https:\/\/geekpython.in\/?p=811"},"modified":"2023-08-15T16:47:15","modified_gmt":"2023-08-15T11:17:15","slug":"zipfile-read-and-write-zip-files-without-extracting-it-in-python","status":"publish","type":"post","link":"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python","title":{"rendered":"zipfile &#8211; Read And Write ZIP Files Without Extracting It In Python"},"content":{"rendered":"\n<p><strong>How often do you work with ZIP files in your day-to-day life?<\/strong><\/p>\n\n\n\n<p>If you ever worked with ZIP files, then you would know that a lot of files and directories are compressed together into one file that has a&nbsp;<em>.zip<\/em>&nbsp;file extension.<\/p>\n\n\n\n<p>So, in order to read that files, we need to extract them from ZIP format.<\/p>\n\n\n\n<p>In this tutorial, we will implement some Pythonic methods for performing various operations on ZIP files without even having to extract them.<\/p>\n\n\n\n<p>For that purpose, we&#8217;ll use Python&#8217;s&nbsp;<code>zipfile<\/code>&nbsp;module to handle the process for us nicely and easily.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-what-is-a-zip-file\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-what-is-a-zip-file\"><\/a>What is a ZIP file?<\/h1>\n\n\n\n<p>As mentioned above, a ZIP file contains one or more files or directories that have been compressed.<\/p>\n\n\n\n<p>ZIP is an&nbsp;<strong>archive file format<\/strong>&nbsp;that supports&nbsp;<strong>lossless data compression<\/strong>.<\/p>\n\n\n\n<p><strong>Lossless compression means that the original data will be perfectly reconstructed from the compressed data without even losing any information.<\/strong><\/p>\n\n\n\n<p>If you wonder what is an archive file, then it is nothing but&nbsp;<strong>computer files that are composed of one or more files along with their metadata<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>This format was originally created in 1989 and was first implemented in PKWARE, Inc.&#8217;s PKZIP utility, as a replacement for the previous ARC compression format by Thom Henderson. The ZIP format was then quickly supported by many software utilities other than PKZIP.<a target=\"_blank\" href=\"https:\/\/en.wikipedia.org\/wiki\/ZIP_(file_format)#:~:text=ZIP%20is%20an%20archive%20file,DEFLATE%20is%20the%20most%20common.\" rel=\"noreferrer noopener\">Source<\/a><\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/diskstructure.png\" alt=\"Disk Structure\" class=\"wp-image-814\" style=\"width:840px;height:455px\" width=\"840\" height=\"455\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Illustration to show how the files are placed on the disk.<a target=\"_blank\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:ZIP-64_Internal_Layout.svg\" rel=\"noreferrer noopener\">Source<\/a><\/p>\n<\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-what-is-the-need-for-a-zip-file\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-what-is-the-need-for-a-zip-file\"><\/a>What is the need for a ZIP file?<\/h1>\n\n\n\n<p>ZIP files can be crucial for those who work with computers and deal with large digital information because it allows them to<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Reduce the storage requirement by compressing the size of the files without the loss of any information<\/strong>.<\/li>\n\n\n\n<li><strong>Improve transfer speed over the network<\/strong>.<\/li>\n\n\n\n<li><strong>Accumulate all your related files into one archive for better management<\/strong>.<\/li>\n\n\n\n<li><strong>Provides security by encrypting the files<\/strong>.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-how-to-manipulate-zip-files-using-python\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-how-to-manipulate-zip-files-using-python\"><\/a>How to manipulate ZIP files using Python?<\/h1>\n\n\n\n<p>Python provides multiple tools to manipulate ZIP files which include some low-level Python libraries such as&nbsp;<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/lzma.html\" rel=\"noreferrer noopener\">lzma<\/a>,&nbsp;<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/bz2.html#module-bz2\" rel=\"noreferrer noopener\">bz2<\/a>,&nbsp;<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/zlib.html#module-zlib\" rel=\"noreferrer noopener\">zlib<\/a>,&nbsp;<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/tarfile.html\" rel=\"noreferrer noopener\">tarfile<\/a>, and many others that help in compressing and decompressing files using specific compression algorithms.<\/p>\n\n\n\n<p>Apart from these Python has a high-level module called&nbsp;<code>zipfile<\/code>&nbsp;that helps us to read, write, create, extract, and list the content of ZIP files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-pythons-zipfile\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-pythons-zipfile\"><\/a>Python&#8217;s zipfile<\/h2>\n\n\n\n<p><code>zipfile<\/code>&nbsp;module does provide convenient classes and functions for reading, writing, and extracting the ZIP files.<\/p>\n\n\n\n<p>But it does have limitations too like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The data decryption process is slow because it runs on pure Python.<\/li>\n\n\n\n<li>It can&#8217;t handle the creation of encrypted ZIP files.<\/li>\n\n\n\n<li>The use of multi-disk ZIP files isn&#8217;t supported currently.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-opening-zip-files-for-reading-andamp-writing\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-opening-zip-files-for-reading-andamp-writing\"><\/a>Opening ZIP files for Reading &amp; Writing<\/h3>\n\n\n\n<p><code>zipfile<\/code>&nbsp;has a class&nbsp;<code>ZipFile<\/code>&nbsp;that allows us to open ZIP files in different modes and works exactly as Python&#8217;s&nbsp;<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/functions.html#open\" rel=\"noreferrer noopener\">open()<\/a>&nbsp;function.<\/p>\n\n\n\n<p>There are four types of modes available &#8211;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>r<\/code>: Opens a file in reading mode. Default<\/li>\n\n\n\n<li><code>w<\/code>: Writing mode.<\/li>\n\n\n\n<li><code>a<\/code>: Append to an existing file.<\/li>\n\n\n\n<li><code>x<\/code>: Create and write a new file.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>ZipFile is also a context manager and therefore supports the&nbsp;<code>with<\/code>&nbsp;statement.<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/zipfile.html\" rel=\"noreferrer noopener\">Source<\/a><\/p>\n<\/blockquote>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"sample.zip\", mode=\"r\") as arch:\n    arch.printdir()\n\n.........\nFile Name                                             Modified             Size\ndocument.txt                                   2022-07-04 18:13:36           52\ndata.txt                                       2022-07-04 18:17:30        37538\nhello.md                                       2022-07-04 18:33:02         7064<\/pre><\/div>\n\n\n\n<p>Here, we can see that all the files present in the&nbsp;<code>sample.zip<\/code>&nbsp;folder have been listed.<\/p>\n\n\n\n<p>Inside&nbsp;<code>ZipFile<\/code>, the&nbsp;<strong>first argument<\/strong>&nbsp;we provided is&nbsp;<strong>the path of the file which is a string<\/strong>.<\/p>\n\n\n\n<p>Then the&nbsp;<strong>second argument<\/strong>&nbsp;we provided is&nbsp;<strong>the mode<\/strong>. Reading mode is default whether you pass it or not it doesn&#8217;t matter.<\/p>\n\n\n\n<p>Then we called&nbsp;<code>.printdir()<\/code>&nbsp;on&nbsp;<code>arch<\/code>&nbsp;which holds the instance of&nbsp;<code>ZipFile<\/code>&nbsp;to&nbsp;<strong>print the table of contents<\/strong>&nbsp;in a user-friendly format<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>File Name<\/li>\n\n\n\n<li>Modified<\/li>\n\n\n\n<li>Size<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-error-handling-by-using-try-andamp-except\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-error-handling-by-using-try-andamp-except\"><\/a>Error Handling by using Try &amp; Except<\/h3>\n\n\n\n<p>We are going to see how&nbsp;<code>zipfile<\/code>&nbsp;handles the exceptions using the&nbsp;<code>BadZipFile<\/code>&nbsp;class that provides an easily readable error.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Provided valid zip file\ntry:\n    with zipfile.ZipFile(\"sample.zip\") as arch:\n        arch.printdir()\nexcept zipfile.BadZipFile as error:\n    print(error)\n\n.........\nFile Name                                             Modified             Size\ndocument.txt                                   2022-07-04 18:13:36           52\ndata.txt                                       2022-07-04 18:17:30        37538\nhello.md                                       2022-07-04 18:33:02         7064\n\n\n# Provided bad zip file\ntry:\n    with zipfile.ZipFile(\"not_valid_zip.zip\") as arch:\n        arch.printdir()\nexcept zipfile.BadZipFile as error:\n    print(error)\n\n.........\nFile is not a zip file<\/pre><\/div>\n\n\n\n<p>The first code block ran successfully and printed the contents of the&nbsp;<code>sample.zip<\/code>&nbsp;file because the ZIP file we provided was a valid ZIP file, whereas&nbsp;<strong>the error was thrown when we provided a bad ZIP file<\/strong>.<\/p>\n\n\n\n<p>We can check if a zip file is valid or not by using&nbsp;<code>is_zipfile<\/code>&nbsp;function.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Example 1\nvalid = zipfile.is_zipfile(\"bad_sample.zip\")\nprint(valid)\n\n.........\nFalse\n\n# Example 2\nvalid = zipfile.is_zipfile(\"sample.zip\")\nprint(valid)\n\n........\nTrue<\/pre><\/div>\n\n\n\n<p>Returns&nbsp;<code>True<\/code>&nbsp;if a file is a valid ZIP file otherwise returns&nbsp;<code>False<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Print content if a file is valid\nif zipfile.is_zipfile(\"sample.zip\"):\n    with zipfile.ZipFile(\"sample.zip\") as arch:\n        arch.printdir()\n\nelse:\n    print(\"This is not a valid ZIP format.\")\n\n.........\nFile Name                                             Modified             Size\ndocument.txt                                   2022-07-04 18:13:36           52\ndata.txt                                       2022-07-04 18:17:30        37538\nhello.md                                       2022-07-04 18:33:02         7064<\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">if zipfile.is_zipfile(\"bad_sample.zip\"):\n    with zipfile.ZipFile(\"sample.zip\") as arch:\n        arch.printdir()\n\nelse:\n    print(\"This is not a valid ZIP format file.\")\n\n.........\nThis is not a valid ZIP format file.<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-writing-the-zip-file\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-writing-the-zip-file\"><\/a>Writing the ZIP file<\/h3>\n\n\n\n<p><strong>To open a ZIP file for writing, use write mode<\/strong>&nbsp;<code>w<\/code>.<\/p>\n\n\n\n<p>If the file you are trying to write exists, then&nbsp;<code>w<\/code>&nbsp;will truncate the existing file and writes new content that you&#8217;ve passed in.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\n# Adding a file\nwith zipfile.ZipFile('geekpython.zip', 'w') as myzip:\n    myzip.write('geek.txt')\n\n    myzip.printdir()\n\n........\nFile Name                                             Modified             Size\ngeek.txt                                       2022-07-05 14:52:01           85<\/pre><\/div>\n\n\n\n<p><code>geek.txt<\/code>&nbsp;will be added to the&nbsp;<code>geekpython.zip<\/code>&nbsp;which is created just now after running the code.<\/p>\n\n\n\n<p><strong>Adding multiple files<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\n# Adding multiple files\nwith zipfile.ZipFile('geekpython.zip', 'w') as myzip:\n    myzip.write('geek.txt')\n    myzip.write('program.py')\n\n    myzip.printdir()\n\n........\nFile Name                                             Modified             Size\ngeek.txt                                       2022-07-05 14:52:01           85\nprogram.py                                     2022-07-05 14:52:01          136<\/pre><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Note: The file you are giving as an argument to<\/strong>&nbsp;<code>.write<\/code>&nbsp;<strong>should exist<\/strong>.<\/p>\n<\/blockquote>\n\n\n\n<p>If you try to create a directory or pass a file that does not exist, it will throw a&nbsp;<code>FileNotFoundError<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\n# Passing a non-existing directory\nwith zipfile.ZipFile('hello\/geekpython.zip', 'w') as myzip:\n    myzip.write('geek.txt')\n\n.........\nFileNotFoundError: [Errno 2] No such file or directory: 'hello\/geekpython.zip'<\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\n# Passing a non-existing file\nwith zipfile.ZipFile('geekpython.zip', 'w') as myzip:\n    myzip.write('hello.txt')\n\n........\nFileNotFoundError: [WinError 2] The system cannot find the file specified: 'hello.txt'<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-appending-files-to-the-existing-zip-archive\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-appending-files-to-the-existing-zip-archive\"><\/a>Appending files to the existing ZIP archive<\/h3>\n\n\n\n<p><strong>To append the files into an existing ZIP archive use append mode<\/strong>&nbsp;<code>a<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\n# Appending files to the existing zip file\nwith zipfile.ZipFile('geekpython.zip', 'a') as myzip:\n    myzip.write(\"index.html\")\n    myzip.write(\"program.py\")\n\n    myzip.printdir()\n\n.........\nFile Name                                             Modified             Size\ngeek.txt                                       2022-07-05 14:52:00           85\nindex.html                                     2022-07-05 15:32:35          176\nprogram.py                                     2022-07-05 14:52:01          136<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-reading-metadata\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-reading-metadata\"><\/a>Reading Metadata<\/h2>\n\n\n\n<p>There are some methods that help us to read the metadata of ZIP archives.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.getinfo(filename)<\/code>: It returns a&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/zipfile.html#zipfile.ZipInfo\" target=\"_blank\">ZipInfo<\/a>&nbsp;object that holds information about the member file provided by&nbsp;<code>filename<\/code>.<\/li>\n\n\n\n<li><code>.infolist()<\/code>: Return a list containing a ZipInfo object for each member of the archive.<\/li>\n\n\n\n<li><code>.namelist()<\/code>: Return a list of archive members by name.<\/li>\n<\/ul>\n\n\n\n<p>There is another function which is&nbsp;<code>.printdir()<\/code>&nbsp;that we already used.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"geekpython.zip\", mode=\"r\") as arch:\n    myzip = arch.getinfo(\"geek.txt\")\n\n\nprint(myzip.filename)\n&gt;&gt;&gt; geek.txt\n\nprint(myzip.date_time)\n&gt;&gt;&gt; (2022, 7, 5, 14, 52, 0)\n\nprint(myzip.file_size)\n&gt;&gt;&gt; 85\n\nprint(myzip.compress_size)\n&gt;&gt;&gt; 85<\/pre><\/div>\n\n\n\n<p>Extracting information about the files in a specified archive using&nbsp;<code>.infolist()<\/code><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\nimport datetime\n\ndate = datetime.datetime\n\nwith zipfile.ZipFile(\"geekpython.zip\", \"r\") as info:\n    for arch in info.infolist():\n        print(f\"The file name is: {arch.filename}\")\n        print(f\"The file size is: {arch.file_size} bytes\")\n        print(f\"The compressed size is: {arch.compress_size} bytes\")\n        print(f\"Date of creation: {date(*arch.date_time)}\")\n\n        print(\"-\" * 15)\n\n.........\nThe file name is: geek.txt\nThe file size is: 85 bytes\nThe compressed size is: 85 bytes\nDate of creation: 2022-07-05 14:52:00\n---------------\nThe file name is: index.html\nThe file size is: 176 bytes\nThe compressed size is: 176 bytes\nDate of creation: 2022-07-05 15:32:34\n---------------\nThe file name is: program.py\nThe file size is: 136 bytes\nThe compressed size is: 136 bytes\nDate of creation: 2022-07-05 14:52:00\n---------------<\/pre><\/div>\n\n\n\n<p>Let&#8217;s see some more methods<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\nwith zipfile.ZipFile(\"sample.zip\", \"r\") as info:\n    for arch in info.infolist():\n        if arch.create_system == 0:\n            system = \"Windows\"\n        elif arch.create_system == 3:\n            system = \"UNIX\"\n        else:\n            system = \"Unknown\"\n\n        print(f\"ZIP version: {arch.create_version}\")\n        print(f\"Create System: {system}\")\n        print(f\"External Attributes: {arch.external_attr}\")\n        print(f\"Internal Attributes: {arch.internal_attr}\")\n        print(f\"Comments: {arch.comment}\")\n\n        print(\"-\" * 15)\n\n.........\nZIP version: 20\nCreate System: Windows\nExternal Attributes: 32\nInternal Attributes: 1\nComments: b''\n---------------\nZIP version: 20\nCreate System: Windows\nExternal Attributes: 32\nInternal Attributes: 1\nComments: b''\n---------------\nZIP version: 20\nCreate System: Windows\nExternal Attributes: 32\nInternal Attributes: 1\nComments: b''\n---------------<\/pre><\/div>\n\n\n\n<p><code>.create_system<\/code>&nbsp;returned an integer<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>0<\/strong>&nbsp;&#8211; for Windows<\/li>\n\n\n\n<li><strong>3<\/strong>&nbsp;&#8211; for Unix<\/li>\n<\/ul>\n\n\n\n<p>Example for showing the use of&nbsp;<code>.namelist()<\/code><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"geekpython.zip\", \"r\") as files:\n    for files_list in files.namelist():\n        print(files_list)\n\n.........\ngeek.txt\nindex.html\nprogram.py<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-reading-and-writing-member-files\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-reading-and-writing-member-files\"><\/a>Reading and Writing Member files<\/h3>\n\n\n\n<p>Member files are referred to as those files which are present inside the ZIP archives.<\/p>\n\n\n\n<p>To read the content of the member file without extracting it, then we use&nbsp;<code>.read()<\/code>. It takes&nbsp;<code>name<\/code>&nbsp;which is the name of the file in an archive and&nbsp;<code>pwd<\/code>&nbsp;is the password used for the encrypted files.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"geekpython.zip\", \"r\") as zif:\n    for lines in zif.read(\"intro.txt\").split(b\"\\r\\n\"):\n        print(lines)\n\n.........\nb'Hey, Welcome to GeekPython!'\nb''\nb'Are you enjoying it?'\nb''\nb\"Now it's time, see you later!\"\nb''<\/pre><\/div>\n\n\n\n<p>We&#8217;ve added&nbsp;<code>.split()<\/code>&nbsp;to print the stream of bytes into lines by using the separator&nbsp;<code>\/r\/n<\/code>&nbsp;and added&nbsp;<code>b<\/code>&nbsp;as a suffix because we are working on the byte object.<\/p>\n\n\n\n<p>Other than&nbsp;<code>.read()<\/code>, we can use&nbsp;<code>.open()<\/code>&nbsp;which allows us to read, write and add a new file in a flexible way because just like&nbsp;<code>open()<\/code>&nbsp;function, it implements context manager protocol and therefore supports&nbsp;<code>with<\/code>&nbsp;statement.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"sample.zip\", \"r\") as my_zip:\n    with my_zip.open(\"document.txt\", \"r\") as data:\n        for text in data:\n            print(text)\n\n.........\nb'Hey, I a document file inside the sample.zip folder.\\r\\n'\nb'\\r\\n'\nb'Are you enjoying it.'<\/pre><\/div>\n\n\n\n<p>We can use&nbsp;<code>.open()<\/code>&nbsp;with write mode&nbsp;<code>w<\/code>&nbsp;to create a new member file and write content to it, and then we can append it to the existing archive.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"sample.zip\", \"a\") as my_zip:\n    with my_zip.open(\"file.txt\", \"w\") as data_file:\n        data_file.write(b\"Hi, I am a new file.\")\n\nwith zipfile.ZipFile(\"sample.zip\", mode=\"r\") as archive:\n    archive.printdir()\n    print(\"-\" * 20)\n    for line in archive.read(\"file.txt\").split(b\"\\n\"):\n        print(line)\n\n.........\nFile Name                                             Modified             Size\ndata.txt                                       2022-07-04 18:17:30        37538\nhello.md                                       2022-07-04 18:33:02         7064\ndocument.txt                                   2022-07-06 17:08:36           76\nfile.txt                                       1980-01-01 00:00:00           20\n--------------------\nb'Hi, I am a new file.'<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-extracting-the-zip-archive\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-extracting-the-zip-archive\"><\/a>Extracting the ZIP archive<\/h3>\n\n\n\n<p>There are 2 methods to extract ZIP archive<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.extractall()<\/code>&nbsp;&#8211; which allows us to extract all members of the archive in the current working directory. We can also specify the path of the directory of our choice.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"geekpython.zip\", \"r\") as file:\n    file.extractall(\"files\")<\/pre><\/div>\n\n\n\n<p>All the member files will be extracted into the folder named&nbsp;<code>files<\/code>&nbsp;in your current working directory. You can specify another directory.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.extract()<\/code>&nbsp;&#8211; allows us to extract a member from the archive to the current working directory. You must keep one thing in mind you need to specify the full name of the member or it must be a&nbsp;<code>ZipInfo<\/code>&nbsp;object.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\nwith zipfile.ZipFile(\"geekpython.zip\", \"r\") as file:\n    file.extract(\"hello.txt\")<\/pre><\/div>\n\n\n\n<p><code>hello.txt<\/code>&nbsp;will be extracted from the archive to the current working directory. You can specify the output directory of your choice. You just need to specify&nbsp;<code>path=\"output_directory\/\"<\/code>&nbsp;as an argument inside the&nbsp;<code>extract()<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-creating-zip-files\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-creating-zip-files\"><\/a>Creating ZIP files<\/h2>\n\n\n\n<p>Creating ZIP files is simply writing existing files.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Creating archive using zipfile module\n\nfiles = [\"hello.txt\", \"geek.md\", \"python.txt\"]\n\nwith zipfile.ZipFile(\"archive_created.zip\", \"w\") as archive:\n    for file in files:\n        archive.write(file)<\/pre><\/div>\n\n\n\n<p>or you can simply add files by directly specifying the full name.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"another_archive.zip\", \"w\") as archive:\n    archive.write(\"hello.txt\")\n    archive.write(\"geek.md\")\n    archive.write(\"python.txt\")<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-creating-zip-files-using-shutil\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-creating-zip-files-using-shutil\"><\/a>Creating ZIP files using&nbsp;<strong>shutil<\/strong><\/h3>\n\n\n\n<p>We can use&nbsp;<code>shutil<\/code>&nbsp;to make a ZIP archive and it provides an easy way of doing it.<\/p>\n\n\n\n<p>The&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/shutil-module-in-python\" target=\"_blank\">Shutil<\/a>&nbsp;module helps in performing high-level file operations in Python.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import shutil\n\nshutil.make_archive(\"archive\", \"zip\", \"files\")<\/pre><\/div>\n\n\n\n<p>Here&nbsp;<code>archive<\/code>&nbsp;is&nbsp;<strong>the file name<\/strong>&nbsp;that will be&nbsp;<strong>created as a ZIP archive<\/strong>,&nbsp;<code>zip<\/code>&nbsp;is the&nbsp;<strong>extension<\/strong>&nbsp;that will be added to the file name, and&nbsp;<code>files<\/code>&nbsp;is a&nbsp;<strong>folder whose data will be archived<\/strong>.<\/p>\n\n\n\n<p>Unpacking the ZIP archive using&nbsp;<code>shutil<\/code><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import shutil\n\nshutil.unpack_archive(\"archive.zip\", \"archive\")<\/pre><\/div>\n\n\n\n<p>Here&nbsp;<code>archive.zip<\/code>&nbsp;is the&nbsp;<strong>ZIP archive<\/strong>&nbsp;and&nbsp;<code>archive<\/code>&nbsp;is the&nbsp;<strong>name of the file to be given after the extraction<\/strong>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-compressing-zip-files\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-compressing-zip-files\"><\/a>Compressing ZIP files<\/h1>\n\n\n\n<p>Usually, when we use&nbsp;<code>zipfile<\/code>&nbsp;to make a ZIP archive, the result we get is actually&nbsp;<strong>uncompressed<\/strong>&nbsp;because by default it uses&nbsp;<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/zipfile.html#zipfile.ZIP_STORED\" rel=\"noreferrer noopener\">ZIP_STORED<\/a>&nbsp;compression method.<\/p>\n\n\n\n<p><strong>It&#8217;s like member files are stored in a container that is archived.<\/strong><\/p>\n\n\n\n<p>So, we need to pass an argument&nbsp;<code>compression<\/code>&nbsp;inside&nbsp;<code>ZipFile<\/code>.<\/p>\n\n\n\n<p>There are 3 types of constants to compress files:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>zipfile.ZIP_DEFLATED<\/code>&nbsp;&#8211; requires a&nbsp;<code>zlib<\/code>&nbsp;module and compression method is&nbsp;<strong>deflate<\/strong>.<\/li>\n\n\n\n<li><code>zipfile.ZIP_BZIP2<\/code>&nbsp;&#8211; requires a&nbsp;<code>bz2<\/code>&nbsp;module and the compression method is&nbsp;<strong>BZIP2<\/strong>.<\/li>\n\n\n\n<li><code>zipfile.ZIP_LZMA<\/code>&nbsp;&#8211; requires a&nbsp;<code>lzma<\/code>&nbsp;module and the compression method is&nbsp;<strong>LZMA<\/strong>.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\nwith zipfile.ZipFile(\"compressed.zip\", \"w\", compression=zipfile.ZIP_DEFLATED) as archive:\n    archive.write(\"geek.md\")\n    archive.write(\"python.txt\")\n    archive.write(\"hello.txt\")<\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\nwith zipfile.ZipFile(\"bzip_compressed.zip\", \"w\", compression=zipfile.ZIP_BZIP2) as archive:\n    archive.write(\"geek.md\")\n    archive.write(\"python.txt\")\n    archive.write(\"hello.txt\")<\/pre><\/div>\n\n\n\n<p>We can also add a&nbsp;<strong>compression level<\/strong>. We can give a value between&nbsp;<code>0<\/code>&nbsp;to&nbsp;<code>9<\/code>&nbsp;for maximum compression.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import zipfile\n\nwith zipfile.ZipFile(\"max_compressed.zip\", \"w\", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as archive:\n    archive.write(\"geek.md\")\n    archive.write(\"python.txt\")\n    archive.write(\"hello.txt\")<\/pre><\/div>\n\n\n\n<p>Did you know that&nbsp;<code>zipfile<\/code>&nbsp;can run from the&nbsp;<strong>command line<\/strong>?<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-run-zipfile-from-command-line-interface\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-run-zipfile-from-command-line-interface\"><\/a>Run zipfile from Command Line Interface<\/h1>\n\n\n\n<p>Here are some options which allow us to list, create, and extract ZIP archives from the command line.<\/p>\n\n\n\n<p><code>-l<\/code>&nbsp;or&nbsp;<code>--list<\/code>: List files in a zipfile.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \">python -m zipfile -l data.zip\n\n.........\nFile Name                                             Modified             Size\nStreamlit-Apps-master\/                         2022-06-30 23:31:36            0\nStreamlit-Apps-master\/Covid-19.csv             2022-06-30 23:31:36         1924\nStreamlit-Apps-master\/Covid-Banner.png         2022-06-30 23:31:36       538140\nStreamlit-Apps-master\/Procfile                 2022-06-30 23:31:36           40\nStreamlit-Apps-master\/Readme.md                2022-06-30 23:31:36          901\nStreamlit-Apps-master\/WebAppPreview.png        2022-06-30 23:31:36       145818\nStreamlit-Apps-master\/app.py                   2022-06-30 23:31:36         3162\nStreamlit-Apps-master\/requirements.txt         2022-06-30 23:31:36           46\nStreamlit-Apps-master\/setup.sh                 2022-06-30 23:31:36          220<\/pre><\/div>\n\n\n\n<p>It just works like&nbsp;<code>.printdir()<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><code>-c<\/code>&nbsp;or&nbsp;<code>--create<\/code>: Create zipfile from source files.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \">python -m zipfile --create shell.zip python.txt hello.txt<\/pre><\/div>\n\n\n\n<p>It will create a ZIP archive named&nbsp;<code>shell.zip<\/code>&nbsp;and add the file names specified above.<\/p>\n\n\n\n<p>Creating a ZIP file to archive the entire directory<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \">python -m zipfile --create directory.zip source\/\n\npython -m zipfile -l directory.zip\n\n.........\nFile Name                                             Modified             Size\nsource\/                                        2022-07-07 17:22:42            0\nsource\/archive\/                                2022-07-07 10:58:06            0\nsource\/archive\/hello.txt                       2022-07-07 10:58:06           62\nsource\/archive\/index.html                      2022-07-07 10:58:06          176\nsource\/archive\/intro.txt                       2022-07-07 10:58:06           86\nsource\/archive\/program.py                      2022-07-07 10:58:06          136\nsource\/geek.md                                 2022-07-07 15:50:28           45\nsource\/hello.txt                               2022-07-07 12:21:22           61<\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><code>-e<\/code>&nbsp;or&nbsp;<code>--extract<\/code>: Extract zipfile into the target directory.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \">python -m zipfile --extract directory.zip extracted\/<\/pre><\/div>\n\n\n\n<p><code>directory.zip<\/code>&nbsp;will be extracted into the&nbsp;<code>extracted<\/code>&nbsp;directory.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><code>-t<\/code>&nbsp;or&nbsp;<code>--test<\/code>: Test whether the zipfile is valid or not.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \">python -m zipfile --test bad_sample.zip\n\n.........\nTraceback (most recent call last):\n...\nBadZipFile: File is not a zip file<\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-conclusion\"><a href=\"https:\/\/geekpython.in\/zipfile-read-and-write-zip-files-without-extracting-it-in-python#heading-conclusion\"><\/a>Conclusion<\/h1>\n\n\n\n<p>Phew, that was a long module to cover, and this article still hasn&#8217;t covered everything.<\/p>\n\n\n\n<p>However, it is sufficient to get started with the&nbsp;<code>zipfile<\/code>&nbsp;module and manipulate ZIP archives without extracting them.<\/p>\n\n\n\n<p>ZIP files do have some benefits like they save disk storage and faster transfer speed over a network and more.<\/p>\n\n\n\n<p>We certainly learned some useful operations that we can perform on ZIP archives with the&nbsp;<code>zipfile<\/code>&nbsp;module, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Read, write, and extract the existing ZIP archives<\/li>\n\n\n\n<li>Reading the metadata<\/li>\n\n\n\n<li>Creating ZIP archives<\/li>\n\n\n\n<li>Manipulating member files<\/li>\n\n\n\n<li>Running&nbsp;<code>zipfile<\/code>&nbsp;from command line<\/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>\u2705What is so special about Python generators and how they work?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/convert-bytes-into-string\" rel=\"noreferrer noopener\">How to convert bytes into a string in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/asterisk-in-python\" rel=\"noreferrer noopener\">Understanding the different uses of asterisk(*) in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/display-images-in-jupyter-notebook\" rel=\"noreferrer noopener\">Different ways to display web and local images in Jupyter Notebook<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/access-list-values-within-the-dictionary\" rel=\"noreferrer noopener\">How to access list items within the dictionary in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/python-sort-vs-sorted\" rel=\"noreferrer noopener\">What is the difference between sort() and sorted() in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/super-in-python\" rel=\"noreferrer noopener\">How to use super() function in Python classes<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/context-managers-and-python-with-statement\" rel=\"noreferrer noopener\">What are context managers in Python<\/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>How often do you work with ZIP files in your day-to-day life? If you ever worked with ZIP files, then you would know that a lot of files and directories are compressed together into one file that has a&nbsp;.zip&nbsp;file extension. So, in order to read that files, we need to extract them from ZIP format. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":813,"comment_status":"open","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":"0","ocean_second_sidebar":"0","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":"0","ocean_custom_header_template":"0","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":"0","ocean_menu_typo_font_family":"0","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":"0","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":"off","ocean_gallery_id":[],"footnotes":""},"categories":[2,42],"tags":[44,43,12,31],"class_list":["post-811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-modules","tag-files","tag-modules","tag-python","tag-python3","entry","has-media"],"_links":{"self":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/811","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=811"}],"version-history":[{"count":5,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/811\/revisions"}],"predecessor-version":[{"id":1371,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/811\/revisions\/1371"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media\/813"}],"wp:attachment":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media?parent=811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/categories?post=811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/tags?post=811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}