pydoc > zipfile

๐Ÿ“› NAME

zipfile - Read and write ZIP files.

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ“‚ Open ZIP for readingzf = ZipFile('archive.zip', 'r')Open existing archive in read mode
โœ๏ธ Create new ZIPzf = ZipFile('new.zip', 'w')Create or overwrite archive
๐Ÿ“Ž Append to ZIPzf = ZipFile('archive.zip', 'a')Add files to existing archive
๐Ÿ“ค Extract allzf.extractall('outdir')Extract everything to a folder
๐Ÿ“ฅ Extract single filezf.extract('file.txt', 'outdir')Extract one member
๐Ÿ“‹ List fileszf.namelist()Get list of archive member names
๐Ÿ” Read file contentdata = zf.read('file.txt')Return bytes of a member
๐Ÿ“ Write string to archivezf.writestr('hello.txt', 'Hello')Write a string as a file
๐Ÿงช Test archive integrityzf.testzip()Check CRC of all files; returns first bad name or None
๐Ÿ” Set passwordzf.setpassword(b'secret')Set default password for encrypted files
โ“ Check if ZIP fileis_zipfile('maybe.zip')Quick magic number check

๐Ÿ“– DESCRIPTION

XXX references to utf-8 need further investigation.

๐Ÿ“š Official Python 3.10 zipfile documentation

๐Ÿ“ฆ CLASSES

โš ๏ธ BadZipFile

class BadZipFile(builtins.Exception)
Aliases: BadZipfile, error (all refer to the same class).

Inherits all methods from Exception and BaseException (__init__, __new__, __str__, __repr__, with_traceback, etc.).

Data descriptors: __weakref__

โš ๏ธ LargeZipFile

class LargeZipFile(builtins.Exception)
Raised when writing a zipfile, the zipfile requires ZIP64 extensions and those extensions are disabled.

Inherits all methods from Exception and BaseException.

Data descriptors: __weakref__

๐Ÿงญ Path

class Path(builtins.object)
Path(root, at='')
A pathlib-compatible interface for zip files.

Consider a zip file with this structure:

.
โ”œโ”€โ”€ a.txt
โ””โ”€โ”€ b
    โ”œโ”€โ”€ c.txt
    โ””โ”€โ”€ d
        โ””โ”€โ”€ e.txt

Example usage:

>>> data = io.BytesIO()
>>> zf = ZipFile(data, 'w')
>>> zf.writestr('a.txt', 'content of a')
>>> zf.writestr('b/c.txt', 'content of c')
>>> zf.writestr('b/d/e.txt', 'content of e')
>>> zf.filename = 'mem/abcde.zip'
>>> root = Path(zf)
>>> a, b = root.iterdir()
>>> a
... Path('mem/abcde.zip', 'a.txt')
>>> b
... Path('mem/abcde.zip', 'b/')
>>> b.name
... 'b'
>>> c = b / 'c.txt'
>>> c.read_text()
... 'content of c'
>>> c.exists()
... True
>>> str(c).replace(os.sep, posixpath.sep)
... 'mem/abcde.zip/b/c.txt'

Methods:

Readonly properties: filename, name, parent.
Data descriptors: __dict__, __weakref__.

๐Ÿ PyZipFile

class PyZipFile(ZipFile)
PyZipFile(file, mode='r', compression=0, allowZip64=True, optimize=-1)
Class to create ZIP archives with Python library files and packages.

Methods defined here:

Inherits all methods from ZipFile (see below).

๐Ÿ—œ๏ธ ZipFile

class ZipFile(builtins.object)
ZipFile(file, mode='r', compression=0, allowZip64=True, compresslevel=None, *, strict_timestamps=True)
Class with methods to open, read, write, close, list zip files.

Parameters:

Methods:

Data descriptors:

๐Ÿ“‹ ZipInfo

class ZipInfo(builtins.object)
ZipInfo(filename='NoName', date_time=(1980, 1, 1, 0, 0, 0))
Class with attributes describing each file in the ZIP archive.

Methods:

Class methods:

Data descriptors (attributes):

๐Ÿ”ง FUNCTIONS

๐Ÿ“Š DATA

๐Ÿ“ FILE

/usr/lib/python3.10/zipfile.py

zipfile
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“– DESCRIPTION ๐Ÿ“ฆ CLASSES
โš ๏ธ BadZipFile โš ๏ธ LargeZipFile ๐Ÿงญ Path ๐Ÿ PyZipFile ๐Ÿ—œ๏ธ ZipFile ๐Ÿ“‹ ZipInfo
๐Ÿ”ง FUNCTIONS ๐Ÿ“Š DATA ๐Ÿ“ FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 18:14 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^