On this page
zipfile.is_zipfile
Prev: zipfile.error | Up: zipfile | Next: zipfile.LargeZipFile
Rel: zipfile.BadZipFile, zipfile.BadZipfile, zipfile.error, zipfile.LargeZipFile
Ref: docs.python.org — zipfile.is_zipfile
Tags: #public #python3 #stdlib #zipfile
Import
import zipfile
from zipfile import is_zipfile
Signature & Overview
zipfile.is_zipfile(filename)
Quickly see if a file is a ZIP file by checking the magic number.
Usage
import io
import zipfile
buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as zf:
zf.writestr("a.txt", "1")
assert zipfile.is_zipfile(buf) is True
assert zipfile.is_zipfile(io.BytesIO(b"plain text")) is False
Gotchas
- Checks the zip magic header/end-of-central-directory only: Does not verify member CRCs—use
zf.testzip()to validate integrity.
REPL Inspect
from zipfile import is_zipfile
help(is_zipfile)
Linked from
- tuts/python3/stdlib_module/zipfile
- tuts/python3/stdlib_module/zipfile/BadZipFile
- tuts/python3/stdlib_module/zipfile/BadZipfile_class
- tuts/python3/stdlib_module/zipfile/error
- tuts/python3/stdlib_module/zipfile/LargeZipFile
- tuts/python3/stdlib_module/zipfile/Path
- tuts/python3/stdlib_module/zipfile/PyZipFile
- tuts/python3/stdlib_module/zipfile/ZipFile
- tuts/python3/stdlib_module/zipfile/ZipInfo
Related notes
- tuts/python3/stdlib_module/zipfile/BadZipFile Linked here; links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/BadZipfile_class Linked here; links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/error Linked here; links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/LargeZipFile Linked here; links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/ZipFile Linked here; links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/Path links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/PyZipFile links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile/ZipInfo links to this page; shared tags: #stdlib, #zipfile
- tuts/python3/stdlib_module/zipfile links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib