Well that's odd. Python's zipfile defaults to the stored compression method, which does not compress! (Why would they do that?)

You need to specify a compression method. Use ZIP_DEFLATED, which is the most widely supported.

import zipfile
zip = zipfile.ZipFile("stuff.zip", "w", zipfile.ZIP_DEFLATED)
zip.write("test.txt")
zip.close()
Answer from Mark Adler on Stack Overflow
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ zipfile.html
zipfile โ€” Work with ZIP archives
February 23, 2026 - ZipFile is also a context manager and therefore supports the with statement. In the example, myzip is closed after the with statementโ€™s suite is finishedโ€”even if an exception occurs:
๐ŸŒ
Real Python
realpython.com โ€บ python-zipfile
Python's zipfile: Manipulate Your ZIP Files Efficiently โ€“ Real Python
January 26, 2025 - Welcome to Real Python! Ready to try Python's zipfile module? In the inner with statement in this example, you open the hello.txt member file from your sample.zip archive. Then you pass the resulting binary file-like object, hello, as an argument to io.TextIOWrapper.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ working-zip-files-python
Working with ZIP Files in Python - GeeksforGeeks
January 19, 2026 - with zipfile.ZipFile("new_file.zip", "w") as zipf: Creates a new ZIP file named new_file.zip in write mode ('w'), overwriting if it already exists. zipf.write("info.txt"): Adds the file info.txt into the ZIP archive. zipf.write("data.txt"): ...
๐ŸŒ
Pythonmania
pythonmania.net โ€บ en โ€บ 2017 โ€บ 06 โ€บ 25 โ€บ zip-files-in-python
Zip files in Python - Python Mania
June 25, 2017 - #!/usr/bin/env python import datetime import zipfile zf = zipfile.ZipFile("example.zip", "r") for info in zf.infolist(): print(info.filename) print(" Comment: " + str(info.comment)) print(" Modified: " + str(datetime.datetime(*info.date_time))) print(" System: " + str(info.create_system) + " (0=MS-DOS OS-2, 3=Unix)") print(" ZIP version: " + str(info.create_version)) print(" Compressed: " + str(info.compress_size) + " bytes") print(" Uncompressed: " + str(info.file_size) + " bytes") zf.close()
๐ŸŒ
SQLPad
sqlpad.io โ€บ tutorial โ€บ python-zipfile
Python zipfile | SQLPad
April 29, 2024 - Learn how to create, read, extract, and modify ZIP archives with practical examples, by using this built-in standard library tool Python's zipfile module.
๐ŸŒ
Medium
medium.com โ€บ @kashishparmar02 โ€บ unzipping-the-power-of-python-zip-libraries-zipfile-vs-pyzipper-128d665ca3ab
Unzipping the Power of Python Zip Libraries: zipfile vs. pyzipper | by Kashish Parmar | Medium
October 15, 2023 - Unzipping the Power of Python Zip Libraries: zipfile vs. pyzipper Table of contents: What is a ZIP file? Significance of file compression Libraries in Python: a brief intro. zipfile Library: pyzipper โ€ฆ
Find elsewhere
๐ŸŒ
Python Module of the Week
pymotw.com โ€บ 3 โ€บ zipfile
zipfile โ€” ZIP Archive Access
Python can import modules from inside ZIP archives using zipimport, if those archives appear in sys.path. The PyZipFile class can be used to construct a module suitable for use in this way. The extra method writepy() tells PyZipFile to scan a directory for .py files and add the corresponding .pyo or .pyc file to the archive. If neither compiled form exists, a .pyc file is created and added. ... import sys import zipfile if __name__ == '__main__': with zipfile.PyZipFile('pyzipfile.zip', mode='w') as zf: zf.debug = 3 print('Adding python files') zf.writepy('.') for name in zf.namelist(): print(name) print() sys.path.insert(0, 'pyzipfile.zip') import zipfile_pyzipfile print('Imported from:', zipfile_pyzipfile.__file__)
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_module_zipfile.asp
Python zipfile Module
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... import zipfile with zipfile.ZipFile('example.zip', 'w') as myzip: myzip.writestr('hello.txt', 'Hello, Emil!') myzip.writestr('data.txt', ...
๐ŸŒ
Medium
medium.com โ€บ @01one โ€บ complete-guide-how-to-zip-and-unzip-files-with-python-c0107700b392
Complete Guide: How to Zip and Unzip Files with Python | by Mashiur Rahman | Medium
October 4, 2025 - import os from zipfile import ZipFile, ... extract ZIP file with size and path validation.""" max_size_bytes = max_size_mb * 1024 * 1024 with ZipFile(zip_filename, 'r') as zipf: # Validate ZIP file try: bad_file = zipf.testzip() if ...
๐ŸŒ
Read the Docs
python.readthedocs.io โ€บ fr โ€บ latest โ€บ library โ€บ zipfile.html
13.5. zipfile โ€” Work with ZIP archives โ€” documentation Python 3.7.0a0
Class for creating ZIP archives containing Python libraries. class zipfile.ZipInfo(filename='NoName', date_time=(1980, 1, 1, 0, 0, 0))ยถ
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ zipfile-python
How to Work with ZIP Files in Python? (Open, Read & Extract)
April 24, 2023 - The ZipFile class is one of the main classes in the module and provides methods for working with ZIP files. To open the file we use the open() function. The open() function is a built-in Python function that takes two arguments: the first argument is the name of the file to be opened, and the second argument specifies the mode in which the file should be opened.
๐ŸŒ
Python Engineer
python-engineer.com โ€บ posts โ€บ python-zip
How to work with ZIP files in Python - Python Engineer
April 30, 2022 - import zipfile with zipfile.ZipFile("./data.zip") as zip: with zip.open("data/assets/index.txt") as fp: print(fp.read().decode())
๐ŸŒ
GitHub
gist.github.com โ€บ drmalex07 โ€บ 10005233
A simple example of using ZIP archives in Python. #python #zip #zipfile ยท GitHub
A simple example of using ZIP archives in Python. #python #zip #zipfile - unpack-zipfile-example.py
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ zip-file
Python zipfile: Zip, Extract, Read & Create Zip Files | DataCamp
November 29, 2018 - If you are not familiar with the error handling, go to Pythons Error Handling documentation to learn the error handling. Let's see all exceptions in zipfile module. zipfile.BadZipFile is an exception in the zipfile module. This error will raise for Bad Zip files. See the example below.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Zip and Unzip Files in Python: zipfile, shutil | note.nkmk.me
August 13, 2023 - In Python, the zipfile module allows you to zip and unzip files, i.e., compress files into a ZIP file and extract a ZIP file. zipfile โ€” Work with ZIP archives โ€” Python 3.11.4 documentation You can a ...
๐ŸŒ
Python Module of the Week
pymotw.com โ€บ 2 โ€บ zipfile
zipfile โ€“ Read and write ZIP archive files - Python Module of the Week
import datetime import zipfile def print_info(archive_name): zf = zipfile.ZipFile(archive_name) for info in zf.infolist(): print info.filename print '\tComment:\t', info.comment print '\tModified:\t', datetime.datetime(*info.date_time) print '\tSystem:\t\t', info.create_system, '(0 = Windows, 3 = Unix)' print '\tZIP version:\t', info.create_version print '\tCompressed:\t', info.compress_size, 'bytes' print '\tUncompressed:\t', info.file_size, 'bytes' print if __name__ == '__main__': print_info('example.zip') There are additional fields other than those printed here, but deciphering the values into anything useful requires careful reading of the PKZIP Application Note with the ZIP file specification. $ python zipfile_infolist.py README.txt Comment: Modified: 2007-12-16 10:08:52 System: 3 (0 = Windows, 3 = Unix) ZIP version: 23 Compressed: 63 bytes Uncompressed: 75 bytes
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ creating-a-zip-archive-of-a-directory-in-python
Creating a Zip Archive of a Directory in Python
September 14, 2023 - Let's take a look at how we can handle these exceptions while creating a zip file: import zipfile try: with zipfile.ZipFile('example.zip', 'w') as myzip: myzip.write('non_existent_file.txt') except FileNotFoundError: print('The file you are trying to zip does not exist.') except RuntimeError ...
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ stdlib โ€บ zipfile
zipfile | Python Standard Library โ€“ Real Python
>>> import pathlib, zipfile >>> ... ... >>> archive_path.exists() True ยท In this example, you create a ZIP archive containing all Python files in a directory, illustrating how the zipfile module can automate the archiving ...