On this page
zipfile.ZipInfo
Prev: zipfile.ZipFile | Up: zipfile
Rel: zipfile.BadZipFile, zipfile.BadZipfile, zipfile.error, zipfile.is_zipfile
Ref: docs.python.org — zipfile.ZipInfo
Tags: #public #python3 #stdlib #zipfile
Import
import zipfile
from zipfile import ZipInfo
Signature & Overview
zipfile.ZipInfo(filename='NoName', date_time=(1980, 1, 1, 0, 0, 0))
Class with attributes describing each file in the ZIP archive.
Methods & Attributes
ZipInfo.FileHeader(self, zip64=None)— Return the per-file header as a bytes object.ZipInfo.from_file(filename, arcname=None, *, strict_timestamps=True)— Construct an appropriate ZipInfo for a file on the filesystem.ZipInfo.is_dir(self)— Return True if this archive member is a directory.
Usage
import io
import zipfile
buf = io.BytesIO()
info = zipfile.ZipInfo("note.txt", date_time=(2026, 12, 2, 12, 0, 0))
info.compress_type = zipfile.ZIP_DEFLATED
with zipfile.ZipFile(buf, "w") as zf:
zf.writestr(info, b"reproducible")
buf.seek(0)
with zipfile.ZipFile(buf, "r") as zf:
zi = zf.getinfo("note.txt")
assert zi.date_time == (2026, 12, 2, 12, 0, 0) and zi.file_size == 12
Gotchas
- Great for reproducible builds: Setting a fixed
ZipInfo(..., date_time=...)produces deterministic zip hashes. - Dates before 1980 raise
ValueError: The ZIP format's DOS timestamp epoch starts at1980-01-01.
REPL Inspect
from zipfile import ZipInfo
help(ZipInfo)
Linked from
Related notes
- tuts/python3/stdlib_module/zipfile/ZipFile Linked here; links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/BadZipFile Linked here; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/BadZipfile_class Linked here; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/error Linked here; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/is_zipfile Linked here; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/zipfile/LargeZipFile shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/Path shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/PyZipFile shared tags: #stdlib, #zipfile
- tuts/c/stdlib shared tags: #stdlib