gzip

Stdlib — CompressionPython 2.0+Intermediate

Read and write gzip-compressed files

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import gzip

data = b"Hello " * 100
compressed = gzip.compress(data)
print(f"Original: {len(data)} bytes")
print(f"Compressed: {len(compressed)} bytes")
print(f"Ratio: {len(compressed)/len(data):.1%}")

decompressed = gzip.decompress(compressed)
print(f"Decompressed matches: {decompressed == data}")

The gzip module is part of Python's standard library. Read and write gzip-compressed files.

Try in Playground

Tags

stdlibcompressionarchive