{"id":22003,"date":"2022-12-23T07:06:00","date_gmt":"2022-12-23T06:06:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=22003"},"modified":"2023-03-23T09:43:37","modified_gmt":"2023-03-23T08:43:37","slug":"zip-and-unzip-files-in-python","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/","title":{"rendered":"How to zip and unzip files with the Python zipfile  module ?"},"content":{"rendered":"\n<h4 class=\"has-text-align-center wp-block-heading\"><strong><em>Tutorial on how to zip and unzip files using Python scripts and the zipfile, shutil and glob librairies?<\/em><\/strong><\/h4>\n\n\n\n<p>If you&#8217;re looking for an easy and efficient way to zip and unzip files with Python zipfile module, then you&#8217;ve come to the right place. In this tutorial, we&#8217;re going to show you how to zip and unzip files in Python. Whether you&#8217;re working with large files or need to compress your data, we&#8217;ve got you covered. So let&#8217;s dive in this Python tutorial.<\/p>\n\n\n\n<p>Zip and unzip files in Python is a common task, and one that can be easily accomplished using built-in libraries. In this tutorial, we&#8217;re going to cover how to zip and unzip files using Python, as well as read, write, and extract data from zip files.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#1-three-python-modules-are-available-to-zip-and-unzip-files\" >1. Three Python modules are available to zip and unzip files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#2-how-to-read-the-content-of-zip-archives-using-python\" >2. How to read the content of zip archives using Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#3-read-metadata-from-zip-files-in-python-scripts\" >3. Read metadata from zip files in Python scripts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#4-python-script-to-open-zip-files-and-read-and-write-data\" >4. Python script to open zip files and read and write data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#5-open-zip-archives-in-write-mode-using-python\" >5. Open zip archives in write mode using Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#6-create-zip-files-using-the-zipfile-python-module\" >6. Create zip files using the zipfile Python module<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#7-read-files-from-zip-archives-in-python\" >7. Read files from zip archives in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#8-uncompress-one-file-from-a-zip-archive\" >8. Uncompress one file from a zip archive<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#9-unzip-multiple-files-with-python-and-zipfile\" >9. Unzip multiple files with Python and zipfile<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#10-how-to-close-a-zip-archive-in-python\" >10. How to close a zip archive in Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#conclusion-on-scripts-to-zip-and-unzip-files-with-python\" >Conclusion on scripts to zip and unzip files with Python<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-three-python-modules-are-available-to-zip-and-unzip-files\"><span class=\"ez-toc-section\" id=\"1-three-python-modules-are-available-to-zip-and-unzip-files\"><\/span>1. Three Python modules are available to zip and unzip files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To <strong>zip and unzip files in Python<\/strong>, you need to import a few libraries. These <strong>modules or libraries are built-in to Python<\/strong> and easy to use. The most commonly used modules to compress and uncompress files into archives are the following : <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>zipfile<\/strong><\/li>\n\n\n\n<li><strong>shutil<\/strong><\/li>\n\n\n\n<li><strong>glob<\/strong><\/li>\n<\/ol>\n\n\n\n<p>For all the examples of code in this tutorial, let&#8217;s consider this <a href=\"https:\/\/expert-only.com\/en\/windows\/how-to-enable-dark-mode-in-windows-10\/\">Windows<\/a> folders and files having this structure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>data<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>source<\/strong>\n<ul class=\"wp-block-list\">\n<li><em>Customers_Data_1.csv<\/em><\/li>\n\n\n\n<li><em>Customers_Data_2.csv<\/em><\/li>\n\n\n\n<li><em>Customers_Data_3.csv<\/em><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><em><strong>Customers_Data_4.csv<\/strong><\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"380\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-folder-structure.jpg\" alt=\"Source files to zip using the zipfile Python modules\" class=\"wp-image-22057\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-folder-structure.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-folder-structure-300x158.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Source files to zip using the zipfile Python modules<\/em><\/strong><\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">1.1 The zipfile module in Python<\/h3>\n\n\n\n<p>The zipfile Python module is a library that is specifically used for working with zip files. It allows you to read and write to zip <a href=\"https:\/\/www.macmillandictionary.com\/dictionary\/british\/file_2\" target=\"_blank\" rel=\"noreferrer noopener\">files<\/a>, as well as extract files from them. The zipfile.ZipFile class is the main class used for working with zip files in this library.<\/p>\n\n\n\n<p>Here&#8217;s a first example of how to extract a file from a zip archive, with the zipfile library. This code opens the <code>files.zip<\/code> file, reads it, and extracts the <code>Customers_Data_1<\/code>.csv file from the archive.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\files.zip', 'r') as archive:\n    archive.extract('Customers_Data_1.csv','C:\\\\data\\\\')\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"380\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-one-file-with-zipfile-module.jpg\" alt=\"Unzip an archive using the Python zipfile module \" class=\"wp-image-22067\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-one-file-with-zipfile-module.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-one-file-with-zipfile-module-300x158.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\">Unzip an archive using the Python zipfile module <\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">1.2 The shutil module in Python<\/h3>\n\n\n\n<p>shutil is a library that provides a higher level interface for working with files and directories. It provides methods for copying, moving, and archiving files and directories. In this case, the shutil.unpack_archive() method can be used to extract the archive. Here&#8217;s an example of how to extract a file from a zip archive using the shutil library. This code extract the archive <code>files.zip<\/code> to the C:\\data\\ directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import shutil\nshutil.unpack_archive('files.zip', 'C:\\\\data\\\\')\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"350\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-all-files-with-shutil-module.jpg\" alt=\"Extract all files from archive with the shutil module in Pyhton\" class=\"wp-image-22073\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-all-files-with-shutil-module.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-all-files-with-shutil-module-300x146.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Extract all files from archive using the shutil module in Python<\/em><\/strong><\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">1.3 The glob Python module<\/h3>\n\n\n\n<p><code>glob<\/code> is a library that allows you to find all the pathnames matching a specified pattern according to the rules used by the Unix shell, although results are returned in arbitrary order. No tangle with the archive itself, but it can be useful to get all the files in a directory with a specific pattern. Here&#8217;s an example of how to extract a file from a zip archive using the <code>glob<\/code> library.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import glob\nimport zipfile\n\nfor file in glob.glob('C:\\\\data\\\\files.zip'):\n    with zipfile.ZipFile(file, 'r') as archive:\n        archive.extract('Customers_Data_2.csv','C:\\\\data\\\\')\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"560\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-one-file-with-glob-module.jpg\" alt=\"Extract and overwrite only the second file named Customers_Data_2.csv using the glob\" class=\"wp-image-22081\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-one-file-with-glob-module.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-one-file-with-glob-module-300x233.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong><em>Extract and overwrite only the second file named Customers_Data_2.csv using the glob<\/em><\/strong><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-how-to-read-the-content-of-zip-archives-using-python\"><span class=\"ez-toc-section\" id=\"2-how-to-read-the-content-of-zip-archives-using-python\"><\/span>2. How to read the content of zip archives using Python?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Reading the contents of a zip file is easy in Python. You can use the <code>zipfile.ZipFile<\/code> class to open a zip file and read its contents. Here&#8217;s an example of how to read the contents of a zip file in Python. This sample script will simply print the contents of the <code>files.zip<\/code> file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\files.zip', 'r') as archive:\n    archive.printdir()\n<\/pre>\n\n\n\n<p>To manage files in a system, like <a href=\"https:\/\/www.linux.org\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Linux<\/a> or Windows, <a href=\"https:\/\/expert-only.com\/en\/python\/manage-files-in-python\/\">Python offers many other modules and built-in functions<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"JVdtv0ou7g\"><a href=\"https:\/\/expert-only.com\/en\/python\/manage-files-in-python\/\">Manage files in Python at file system level<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Manage files in Python at file system level&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/python\/manage-files-in-python\/embed\/#?secret=97SP2MPYnr#?secret=JVdtv0ou7g\" data-secret=\"JVdtv0ou7g\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-read-metadata-from-zip-files-in-python-scripts\"><span class=\"ez-toc-section\" id=\"3-read-metadata-from-zip-files-in-python-scripts\"><\/span>3. Read metadata from zip files in Python scripts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also read metadata from zip files in Python. You can use the <code>zipfile.ZipInfo<\/code> class to get information about the zip file, such as the file name, date, and size. Here&#8217;s an example of how to read metadata from a zip file in Python. This will print the following information&#8217;s:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Filename<\/li>\n\n\n\n<li>Last modified date with Year, Month, Day, Hour, Minutes and Seconds<\/li>\n\n\n\n<li>And the size of each file in bytes.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\files.zip', 'r') as archive:\n    for info in archive.infolist():\n        print(info.filename, info.date_time, info.file_size)\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"360\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-display-archive-metadata-with-zipfile.jpg\" alt=\"Read the ZIP archive metadata with the Python infolist function\" class=\"wp-image-22142\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-display-archive-metadata-with-zipfile.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-display-archive-metadata-with-zipfile-300x150.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\">Read the ZIP archive metadata with the Python infolist function<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4-python-script-to-open-zip-files-and-read-and-write-data\"><\/span>4. Python script to open zip files and read and write data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also open zip files in Python to read and write data. You can use the <code>zipfile.ZipFile<\/code> class to open a zip file, and then use the <code>write()<\/code> and <code>extract()<\/code> methods to add or extract files. Let&#8217;s say we want to add the file called <code>Customers_Data_4.csv<\/code> to the previous <code>files.zip<\/code> archive. This example below will add the file to zip archive. We use here the <strong><em>append mode<\/em><\/strong> to open the file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\files.zip', 'a') as archive:\n    archive.write('C:\\\\data\\\\Customers_Data_4.csv','Customers_Data_4.csv')\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5-open-zip-archives-in-write-mode-using-python\"><\/span>5. Open zip archives in write mode using Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also open zip files in Python to write data. You can use the <code>zipfile.ZipFile<\/code> class to create a new zip file, and then use the <code>write()<\/code> method to add files to it. Here&#8217;s an example of how to create a new zip file in Python and add a file to it. This will create a new zip file called <code>new_files.zip<\/code> and add <code>Customers_Data_1<\/code>.csv to it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\new_files.zip', 'w') as archive:\n    archive.write('C:\\\\data\\\\Customers_Data_1.csv','Customers_Data_1.csv')\n<\/pre>\n\n\n\n<p>Let&#8217;s break down the Python code above: <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Import the <em>zipfile module<\/em><\/li>\n\n\n\n<li>Create a new ZIP archive in write mode, called <em>new_files.zip<\/em><\/li>\n\n\n\n<li>Add to the archive the CSV file called <em>Customers_Data_1.csv<\/em><\/li>\n<\/ol>\n\n\n\n<p>Note that you have to use the <strong>double escape characters \\\\<\/strong> when using <a href=\"https:\/\/expert-only.com\/en\/ms-dos\/list-files-recursively-with-cmd\/\">Windows files and folders<\/a>, in order to escape the escape character itself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6-create-zip-files-using-the-zipfile-python-module\"><\/span>6. Create zip files using the zipfile Python module<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also create zip archives in Python using the <code>shutil<\/code> library. The <code>shutil.make_archive()<\/code> function can be used to create a zip archive from a directory. Here&#8217;s an example of how to create a zip archive from a directory in Python. The goal here is to create a zip archive with this path <strong>C:\\data\\files.zip<\/strong> from the content of the <strong>C:\\data\\source<\/strong> folder, and after that, display the content from the zip itself.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import shutil\nimport zipfile\n\nshutil.make_archive('C:\\\\data\\\\files', 'zip', 'C:\\\\data\\\\source')\n\nwith zipfile.ZipFile('C:\\\\data\\\\files.zip', 'r') as archive:\n    archive.printdir()\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"420\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-content-and-display-archive.jpg\" alt=\"Zip content of the source folder and display content from zip archive in Python\" class=\"wp-image-22087\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-content-and-display-archive.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-zip-unzip-content-and-display-archive-300x175.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\">Zip content of the source folder and display content from zip archive in Python<\/figcaption><\/figure><\/div>\n\n\n<p>As you may know, zipping files is a common task in data management projects, and especially with the data integration and ETL projects. For example, it is possible to <a href=\"https:\/\/expert-only.com\/en\/ssis\/zip-files-with-ssis\/\">zip files and folders using SSIS and 7Zip<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"vFmOtE8eKI\"><a href=\"https:\/\/expert-only.com\/en\/ssis\/zip-files-with-ssis\/\">Zip files with SSIS and 7zip<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Zip files with SSIS and 7zip&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/ssis\/zip-files-with-ssis\/embed\/#?secret=tk2eoxyhyw#?secret=vFmOtE8eKI\" data-secret=\"vFmOtE8eKI\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7-read-files-from-zip-archives-in-python\"><\/span>7. Read files from zip archives in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you need to zip and unzip files with the Python zipfile module, it is very convenient to also read from files directly in zip archives. You can use the <code>zipfile.ZipFile<\/code> class to open a zip file, and then use the <code>extract()<\/code> method to extract a file.<\/p>\n\n\n\n<p>Now let&#8217;s try together to do the opposite operation, i.e., read the same files from the 2 archives we created in the previous steps, called <strong><em>files.zip<\/em><\/strong> and <strong><em>new_files.zip<\/em><\/strong>. To perform this extraction, copy and paste the Python script below.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># read from the first ZIP archive\nprint('--- FIRST FILE ---')\nimport zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\files.zip', 'r') as archive:\n    archive.printdir()\n\n\n# read from the second ZIP archive\nprint('--- SECOND FILE ---')\nimport zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\new_files.zip', 'r') as archive:\n    archive.printdir()\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"600\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-read-files-from-archives-with-zipfile-and-printdir.jpg\" alt=\"Read files and folders from a ZIP archive using the zipfile Python module\" class=\"wp-image-22135\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-read-files-from-archives-with-zipfile-and-printdir.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/01\/python-read-files-from-archives-with-zipfile-and-printdir-300x250.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong>Read files and folders from a ZIP archive using the zipfile Python module<\/strong><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8-uncompress-one-file-from-a-zip-archive\"><\/span>8. Uncompress one file from a zip archive<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also extract one file from a zip archive in Python. You can use the <code>zipfile.ZipFile<\/code> class to open a zip file, and then use the <code>extract()<\/code> method to extract a specific file from the archive. To build a script to extract a given file from a zip archive in Python, use this script and adapt it to your current settings.<\/p>\n\n\n\n<p>In the example of script below, again we <strong>use the explicit path to extract the file<\/strong>. If the path is not provided, the export path is the default Python path.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\new_files.zip', 'r') as archive:\n    archive.extract('Customers_Data_1.csv','C:\\\\data\\\\')\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9-unzip-multiple-files-with-python-and-zipfile\"><\/span>9. Unzip multiple files with Python and zipfile<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Unzipping multiple files at once in Python<\/strong> is also easy. Simple use the <code>shutil<\/code> library and its <code>unpack_archive()<\/code> method to unzip the content of a file. This will unzip the <code>files.zip<\/code> file to the <code>C:\\data<\/code> directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import shutil\nshutil.unpack_archive('C:\\\\data\\\\files.zip', 'C:\\\\data\\\\')\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"10-how-to-close-a-zip-archive-in-python\"><\/span>10. How to close a zip archive in Python?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>It is important to close a zip archive once you are done with it, this can be done by using the <code>close()<\/code> method from the <code>zipfile.ZipFile<\/code> class.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import zipfile\nwith zipfile.ZipFile('C:\\\\data\\\\files.zip', 'r') as archive:\n    #scripts to read or write to manipulate the archive content\n    archive.close()\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"conclusion-on-scripts-to-zip-and-unzip-files-with-python\"><\/span>Conclusion on scripts to zip and unzip files with Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In conclusion, it is relatively easy <strong>to zip and unzip files with Python zipfile module<\/strong>. Indeed, with the built-in functions from the modules available, it is a straightforward task. You can use built-in libraries such as <strong><em>zipfile<\/em><\/strong>, <strong><em>shutil<\/em><\/strong>, and <strong><em>glob<\/em><\/strong> to easily read, write, and extract data from zip archives.<\/p>\n\n\n\n<p>With the multiple examples provided in this tutorial, you should now be able to compress and uncompress files in Python with confidence. The next step after zipping and unzipping files might be to <a href=\"https:\/\/expert-only.com\/en\/python\/text-files-in-python\/\">read and write the content of the files itself<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"yFoyao4chr\"><a href=\"https:\/\/expert-only.com\/en\/python\/text-files-in-python\/\">Manage text files in Python using read and write methods<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Manage text files in Python using read and write methods&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/python\/text-files-in-python\/embed\/#?secret=YGAWAUdUSy#?secret=yFoyao4chr\" data-secret=\"yFoyao4chr\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Tutorial on how to zip and unzip files using Python scripts and the zipfile, shutil and glob librairies? If you&#8217;re looking for an easy and efficient way to zip and unzip files with Python zipfile module, then you&#8217;ve come <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\" title=\"How to zip and unzip files with the Python zipfile  module ?\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":10864,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[657],"tags":[],"class_list":{"0":"post-22003","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to zip and unzip files with the Python zipfile module ?<\/title>\n<meta name=\"description\" content=\"To zip and unzip files with the Python zipfile module, use also shutil and glob in scripts to read, write, and extract data from archives.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to zip and unzip files with the Python zipfile module ?\" \/>\n<meta property=\"og:description\" content=\"To zip and unzip files with the Python zipfile module, use also shutil and glob in scripts to read, write, and extract data from archives.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-23T06:06:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-23T08:43:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"How to zip and unzip files with the Python zipfile module ?\",\"datePublished\":\"2022-12-23T06:06:00+00:00\",\"dateModified\":\"2023-03-23T08:43:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\"},\"wordCount\":1427,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg\",\"articleSection\":[\"Python tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\",\"url\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\",\"name\":\"How to zip and unzip files with the Python zipfile module ?\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg\",\"datePublished\":\"2022-12-23T06:06:00+00:00\",\"dateModified\":\"2023-03-23T08:43:37+00:00\",\"description\":\"To zip and unzip files with the Python zipfile module, use also shutil and glob in scripts to read, write, and extract data from archives.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to zip and unzip files with the Python zipfile module ?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to zip and unzip files with the Python zipfile module ?","description":"To zip and unzip files with the Python zipfile module, use also shutil and glob in scripts to read, write, and extract data from archives.","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:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to zip and unzip files with the Python zipfile module ?","og_description":"To zip and unzip files with the Python zipfile module, use also shutil and glob in scripts to read, write, and extract data from archives.","og_url":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-12-23T06:06:00+00:00","article_modified_time":"2023-03-23T08:43:37+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"How to zip and unzip files with the Python zipfile module ?","datePublished":"2022-12-23T06:06:00+00:00","dateModified":"2023-03-23T08:43:37+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/"},"wordCount":1427,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg","articleSection":["Python tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/","url":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/","name":"How to zip and unzip files with the Python zipfile module ?","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg","datePublished":"2022-12-23T06:06:00+00:00","dateModified":"2023-03-23T08:43:37+00:00","description":"To zip and unzip files with the Python zipfile module, use also shutil and glob in scripts to read, write, and extract data from archives.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/texture-design-7E25D084595_1920x1080.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/python\/zip-and-unzip-files-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to zip and unzip files with the Python zipfile module ?"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/22003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=22003"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/22003\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/10864"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=22003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=22003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=22003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}