gzip — Easy Examples
Read and write gzip-compressed files
Getting started with gzip
Basic import and usage of the gzip module.
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.
Common gzip operations
Frequently used functions from the gzip module.
python
# More gzip examples import gzip print(f"gzip module loaded successfully") print(f"Location: {gzip.__name__}") print(f"Has {len(dir(gzip))} attributes")
These are the most commonly used features of the gzip module.
Want to try these examples interactively?
Open Easy Playground