Compression and Archives Modules

zlib

Provides DEFLATE compression, incremental stream objects and checksum functions. The default compress() produces a zlib-wrapped stream, not a ZIP archive or a gzip file. Match decompressor settings to the input format. Bound decompression resources for external inputs; compression is not encryption or authentication.

Formal Syntax & Structure

python syntaxpython
import zlib

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import zlibraw = b"tea tea tea"packed = zlib.compress(raw)print(zlib.decompress(packed))
Python Reference