On this page
  1. gzip.compress
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

gzip.compress

Prev: gzip.BadGzipFile | Up: gzip | Next: gzip.decompress
Rel: gzip.BadGzipFile, gzip.decompress, gzip.GzipFile, gzip.open
Ref: docs.python.org — gzip.compress
Tags: #public #python3 #stdlib #gzip


Import

import gzip
from gzip import compress

Signature & Overview

gzip.compress(data, compresslevel=9, *, mtime=0)

Compress data in one shot and return the compressed string.

Usage

import gzip

raw = b"hello " * 50
packed = gzip.compress(raw, mtime=0)
assert len(packed) < len(raw) and gzip.decompress(packed) == raw

Gotchas

REPL Inspect

from gzip import compress
help(compress)

Linked from

Related notes