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"): ...
๐ŸŒ
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', ...
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
Python Module of the Week
pymotw.com โ€บ 3 โ€บ zipfile
zipfile โ€” ZIP Archive Access โ€” PyMOTW 3
import datetime import zipfile def print_info(archive_name): with zipfile.ZipFile(archive_name) as zf: for info in zf.infolist(): print(info.filename) print(' Comment :', info.comment) mod_date = datetime.datetime(*info.date_time) print(' Modified :', mod_date) if info.create_system == 0: system = 'Windows' elif info.create_system == 3: system = 'Unix' else: system = 'UNKNOWN' print(' System :', system) print(' ZIP version :', info.create_version) print(' Compressed :', info.compress_size, 'bytes') print(' Uncompressed:', info.file_size, 'bytes') print() if __name__ == '__main__': print_info('
๐ŸŒ
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 Cheatsheet
pythoncheatsheet.org โ€บ home โ€บ modules โ€บ zipfile module
Python Zipfile Module - Python Cheatsheet
November 15, 2022 - # Extract a single file from ZIP with zipfile.ZipFile('example.zip') as example_zip: # Extract to current directory (returns path) print(example_zip.extract('spam.txt')) # Extract to a specific directory print(example_zip.extract('spam.txt', ...
๐ŸŒ
Python
docs.python.org โ€บ 3.9 โ€บ library โ€บ zipfile.html
zipfile โ€” Work with ZIP archives โ€” Python 3.9.24 documentation
Class for creating ZIP archives containing Python libraries. class zipfile.ZipInfo(filename='NoName', date_time=(1980, 1, 1, 0, 0, 0))ยถ
๐ŸŒ
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
๐ŸŒ
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())
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ python โ€บ python zip file with example
Python ZIP file with Example
August 12, 2024 - Step 4) In Python we can have more control over archive since we can define which specific file to include under archive. In our case, we will include two files under archive โ€œguru99.txtโ€ and โ€œguru99.txt.bakโ€. ... Import Zipfile class from zip file Python module.
๐ŸŒ
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 ...
๐ŸŒ
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 ...