Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

How to Unzip a File in Python

Use Python’s built-in zipfile module to extract a whole archive or one selected file, with a command-line option and safety tips.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Python’s built-in zipfile module to extract a ZIP archive: open it with ZipFile, then call extractall() for every file or extract() for one selected member. No extra package is needed for basic ZIP extraction.

Extract every file from a ZIP archive

Pass the archive path to ZipFile and the destination folder to extractall(). The context manager closes the archive automatically when extraction finishes.

from zipfile import ZipFile

with ZipFile("archive.zip") as archive:
    archive.extractall("output_folder")

Replace archive.zip with your ZIP file’s path and output_folder with the folder where you want its contents placed. If you omit the destination argument, extraction targets the current working directory.

Extract just one file

Use extract() and provide the member’s name as it appears inside the archive. The second argument sets the destination folder.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from zipfile import ZipFile

with ZipFile("archive.zip") as archive:
    archive.extract("reports/summary.csv", "output_folder")

If you do not know the exact member name, list the archive contents first:

from zipfile import ZipFile

with ZipFile("archive.zip") as archive:
    print(archive.namelist())

namelist() returns the names of the members. Use one of those names in extract(); infolist() is another option when you need each member’s ZipInfo record. See the Python 3.14.8 zipfile documentation for the API details.

Unzip from the command line instead

For a one-off extraction that does not need to be part of a Python script, use the standard-library command-line interface:

python -m zipfile -e archive.zip output_folder

To list the members, use -l; to test whether the archive is valid, use -t. These options are documented in the Python zipfile reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Handle untrusted ZIP files carefully

Python’s documentation warns: “Never extract archives from untrusted sources without prior inspection.” ZIP member names can contain absolute paths or .. components that attempt to write outside the chosen folder. The extraction methods try to prevent this, but the zipfile.Path interface does not sanitize names; if you use it with untrusted archives, validate paths yourself.

Also consider whether the archive could expand to consume excessive disk space. A decompression bomb can exhaust available storage. Check the archive’s source, member names and expected output size, and make sure you have enough disk space before extracting it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot extraction errors

Extraction can fail for several documented reasons. Check the archive and environment for these common causes:

  • Invalid ZIP: The file may be damaged or not be a valid ZIP archive.
  • Password issue: An encrypted member may require the correct password.
  • Unsupported compression: The archive may use a compression method Python cannot handle, or an optional compression module may be unavailable.
  • Filesystem limits: The destination filesystem may restrict a path or filename length, or prevent writing to the destination.
  • Insufficient resources: Extraction may require more memory or disk space than is available.

Choose the destination with care: extracting again may overwrite existing files without prompting. The Python documentation for zipfile describes these limitations and security considerations.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.