Compression and Archives Modules
gzip
gzip wraps DEFLATE-compressed data in a gzip container. gzip.open() supports compressed binary or encoded text streams; compress() and decompress() work on bytes. Set mtime explicitly when reproducible metadata matters. Bound decompression resources for external inputs; compression is not encryption or authentication.
Formal Syntax & Structure
python syntaxpython
import gzipReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import gzipraw = b"tea tea tea"packed = gzip.compress(raw, mtime=0)print(gzip.decompress(packed))