Compression and Archives Modules

bz2

Bzip2 compression supports one-shot byte transforms, compressed files and incremental compressor/decompressor objects. Use bz2.open() for file streams. Bound decompression resources for external inputs; compression is not encryption or authentication.

Formal Syntax & Structure

python syntaxpython
import bz2

Return Value

module

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

Working Example

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