Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Using Other Libraries to Manage ZIP Files

00:00 Using Other Libraries to Manage ZIP Files. There are a few other tools in the Python standard library that you can use to archive, compress, and decompress your files at a lower level. Python’s zipfile uses some of these internally, mainly for compression purposes.

00:16 On-screen is a summary of these tools. Unlike zipfile, some of these modules allow you to compress and decompress data from memory and data streams other than regular files and archives.

00:28 In the Python standard library, you’ll also find tarfile, which supports the TAR archiving format. There’s also a module called gzip, which provides an interface to compress and decompress data, similar to how the new GNU Gzip program does it.

00:45 For example, you can use gzip to create a compressed file containing some text.

01:04 Once you run this code, you’ll have a hello.txt.gz archive containing a compressed version of hello.txt in your current directory. Inside hello.txt, you’ll find the text Hello, World!.

01:21 A quick and high-level way to create a ZIP file without using zipfile is to use shutil. This module allows you to perform several high-level operations on files and collections of files. When it comes to archiving operations, you have make_archive(), which can create archives such as ZIP or TAR files.

01:46 This code creates a compressed file called shutil_sample.zip in your working directory. This ZIP file will contain all the files in the input directory, source_dir/.

01:59 The make_archive() function is convenient when you need a quick and high-level way to create your ZIP files in Python. In the next section of the course, you’ll take a look back at what you’ve covered.

Become a Member to join the conversation.