class documentation

Class with methods to open, read, write, close, list zip files.

z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True,
compresslevel=None)
file: Either the path to the file, or a file-like object.
If it is a path, the file will be opened and closed by ZipFile.
mode: The mode can be either read 'r', write 'w', exclusive create 'x',
or append 'a'.
compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).
allowZip64: if True ZipFile will create files with ZIP64 extensions when
needed, otherwise it will raise an exception when this would be necessary.
compresslevel: None (default for the given compression type) or an integer
specifying the level to pass to the compressor. When using ZIP_STORED or ZIP_LZMA this keyword has no effect. When using ZIP_DEFLATED integers 0 through 9 are accepted. When using ZIP_BZIP2 integers 1 through 9 are accepted.
Method __del__ Call the "close()" method in case the user forgot.
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.
Method __repr__ Undocumented
Method close Close the file, and for mode 'w', 'x' and 'a' write the ending records.
Method comment.setter Undocumented
Method extract Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using ...
Method extractall Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist()...
Method getinfo Return the instance of ZipInfo given 'name'.
Method infolist Return a list of class ZipInfo instances for files in the archive.
Method mkdir Creates a directory inside the zip archive.
Method namelist Return a list of file names in the archive.
Method open Return file-like object for 'name'.
Method printdir Print a table of contents for the zip file.
Method read Return file bytes for name. 'pwd' is the password to decrypt encrypted files.
Method setpassword Set default password for encrypted files.
Method testzip Read all the files and check the CRC.
Method write Put the bytes from filename into the archive under the name arcname.
Method writestr Write a file into the archive. The contents is 'data', which may be either a 'str' or a 'bytes' instance; if it is a 'str', it is encoded as UTF-8 first. 'zinfo_or_arcname' is either a ZipInfo instance or the name of the file in the archive.
Instance Variable compression Undocumented
Instance Variable compresslevel Undocumented
Instance Variable debug Undocumented
Instance Variable filelist Undocumented
Instance Variable filename Undocumented
Instance Variable fp Undocumented
Instance Variable metadata_encoding Undocumented
Instance Variable mode Undocumented
Instance Variable NameToInfo Undocumented
Instance Variable pwd Undocumented
Instance Variable start_dir Undocumented
Property comment The comment text associated with the ZIP file.
Class Method _sanitize_windows_name Replace bad characters and remove trailing dots from parts.
Method _extract_member Extract the ZipInfo object 'member' to a physical file on the path targetpath.
Method _fpclose Undocumented
Method _open_to_write Undocumented
Method _RealGetContents Read in the table of contents for the ZIP file.
Method _write_end_record Undocumented
Method _writecheck Check for errors before writing a file to the archive.
Class Variable _windows_illegal_name_trans_table Undocumented
Instance Variable _allowZip64 Undocumented
Instance Variable _comment Undocumented
Instance Variable _didModify Undocumented
Instance Variable _filePassed Undocumented
Instance Variable _fileRefCnt Undocumented
Instance Variable _lock Undocumented
Instance Variable _seekable Undocumented
Instance Variable _strict_timestamps Undocumented
Instance Variable _writing Undocumented
def __del__(self):

Call the "close()" method in case the user forgot.

def __enter__(self):

Undocumented

def __exit__(self, type, value, traceback):

Undocumented

def __init__(self, file, mode='r', compression=ZIP_STORED, allowZip64=True, compresslevel=None, *, strict_timestamps=True, metadata_encoding=None):

Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.

def __repr__(self):

Undocumented

def close(self):

Close the file, and for mode 'w', 'x' and 'a' write the ending records.

def comment(self, comment):

Undocumented

def extract(self, member, path=None, pwd=None):

Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using `path'. You can specify the password to decrypt the file using 'pwd'.

def extractall(self, path=None, members=None, pwd=None):

Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist(). You can specify the password to decrypt all files using 'pwd'.

def getinfo(self, name):

Return the instance of ZipInfo given 'name'.

def infolist(self):

Return a list of class ZipInfo instances for files in the archive.

def mkdir(self, zinfo_or_directory_name, mode=511):

Creates a directory inside the zip archive.

def namelist(self):

Return a list of file names in the archive.

def open(self, name, mode='r', pwd=None, *, force_zip64=False):

Return file-like object for 'name'.

name is a string for the file name within the ZIP file, or a ZipInfo object.

mode should be 'r' to read a file already in the ZIP file, or 'w' to write to a file newly added to the archive.

pwd is the password to decrypt files (only used for reading).

When writing, if the file size is not known in advance but may exceed 2 GiB, pass force_zip64 to use the ZIP64 format, which can handle large files. If the size is known in advance, it is best to pass a ZipInfo instance for name, with zinfo.file_size set.

def printdir(self, file=None):

Print a table of contents for the zip file.

def read(self, name, pwd=None):

Return file bytes for name. 'pwd' is the password to decrypt encrypted files.

def setpassword(self, pwd):

Set default password for encrypted files.

def testzip(self):

Read all the files and check the CRC.

Return None if all files could be read successfully, or the name of the offending file otherwise.

def write(self, filename, arcname=None, compress_type=None, compresslevel=None):

Put the bytes from filename into the archive under the name arcname.

def writestr(self, zinfo_or_arcname, data, compress_type=None, compresslevel=None):

Write a file into the archive. The contents is 'data', which may be either a 'str' or a 'bytes' instance; if it is a 'str', it is encoded as UTF-8 first. 'zinfo_or_arcname' is either a ZipInfo instance or the name of the file in the archive.

compression =

Undocumented

compresslevel =

Undocumented

debug: int =

Undocumented

filelist: list =

Undocumented

filename =

Undocumented

fp =

Undocumented

metadata_encoding =

Undocumented

mode =

Undocumented

NameToInfo: dict =

Undocumented

pwd =

Undocumented

start_dir =

Undocumented

@property
comment =

The comment text associated with the ZIP file.

@classmethod
def _sanitize_windows_name(cls, arcname, pathsep):

Replace bad characters and remove trailing dots from parts.

def _extract_member(self, member, targetpath, pwd):

Extract the ZipInfo object 'member' to a physical file on the path targetpath.

def _fpclose(self, fp):

Undocumented

def _open_to_write(self, zinfo, force_zip64=False):

Undocumented

def _RealGetContents(self):

Read in the table of contents for the ZIP file.

def _write_end_record(self):

Undocumented

def _writecheck(self, zinfo):

Check for errors before writing a file to the archive.

_windows_illegal_name_trans_table =

Undocumented

_allowZip64 =

Undocumented

_comment =

Undocumented

_didModify: bool =

Undocumented

_filePassed: int =

Undocumented

_fileRefCnt: int =

Undocumented

_lock =

Undocumented

_seekable: bool =

Undocumented

_strict_timestamps =

Undocumented

_writing: bool =

Undocumented