pydoc > lzma

📝 NAME

lzma - Interface to the liblzma compression library.

🚀 Quick Reference

Use CaseCommandDescription
Open LZMA file for reading (binary)lzma.open(filename, 'rb')Open an LZMA-compressed file in binary read mode
Open LZMA file for writing (binary)lzma.open(filename, 'wb')Open an LZMA-compressed file for binary writing
One-shot compress datalzma.compress(data)Compress a block of data using default settings
One-shot decompress datalzma.decompress(data)Decompress a block of data (auto-detects format)
Incremental compressionlzma.LZMACompressor()Create compressor object for streaming compression
Incremental decompressionlzma.LZMADecompressor()Create decompressor object for streaming decompression
Check integrity supportlzma.is_check_supported(check_id)Test whether a given integrity check is supported

📚 MODULE REFERENCE

https://docs.python.org/3.10/library/lzma.html

The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.

📖 DESCRIPTION

This module provides a class for reading and writing compressed files, classes for incremental (de)compression, and convenience functions for one-shot (de)compression.

These classes and functions support both the XZ and legacy LZMA container formats, as well as raw compressed data streams.

📦 CLASSES

_compression.BaseStream(io.BufferedIOBase)LZMAFile

builtins.Exception(builtins.BaseException)_lzma.LZMAError

builtins.object_lzma.LZMACompressor, _lzma.LZMADecompressor

🔧 LZMACompressor

LZMACompressor(format=FORMAT_XZ, check=-1, preset=None, filters=None)

Create a compressor object for compressing data incrementally.

format specifies the container format to use for the output. This can be FORMAT_XZ (default), FORMAT_ALONE, or FORMAT_RAW.

check specifies the integrity check to use. For FORMAT_XZ, the default is CHECK_CRC64. FORMAT_ALONE and FORMAT_RAW do not support integrity checks; for these formats, check must be omitted, or be CHECK_NONE.

The settings used by the compressor can be specified either as a preset compression level (with the 'preset' argument), or in detail as a custom filter chain (with the 'filters' argument). For FORMAT_XZ and FORMAT_ALONE, the default is to use the PRESET_DEFAULT preset level. For FORMAT_RAW, the caller must always specify a filter chain; the raw compressor does not support preset compression levels.

preset (if provided) should be an integer in the range 0-9, optionally OR-ed with the constant PRESET_EXTREME.

filters (if provided) should be a sequence of dicts. Each dict should have an entry for "id" indicating the ID of the filter, plus additional entries for options to the filter.

For one-shot compression, use the compress() function instead.

🔧 Methods defined here:

⚙️ Static methods defined here:

🔧 LZMADecompressor

LZMADecompressor(format=0, memlimit=None, filters=None)

Create a decompressor object for decompressing data incrementally.

Parameters:

For one-shot decompression, use the decompress() function instead.

🔧 Methods defined here:

⚙️ Static methods defined here:

📊 Data descriptors defined here:

⚠️ LZMAError

Call to liblzma failed.

Method resolution order: LZMAError, builtins.Exception, builtins.BaseException, builtins.object

📊 Data descriptors defined here:

🔧 Methods inherited from builtins.Exception:

⚙️ Static methods inherited from builtins.Exception:

🔧 Methods inherited from builtins.BaseException:

📊 Data descriptors inherited from builtins.BaseException:

📂 LZMAFile

LZMAFile(filename=None, mode='r', *, format=None, check=-1, preset=None, filters=None)

A file object providing transparent LZMA (de)compression.

An LZMAFile can act as a wrapper for an existing file object, or refer directly to a named file on disk.

Note that LZMAFile provides a binary file interface - data read is returned as bytes, and data to be written must be given as bytes.

Method resolution order: LZMAFile, _compression.BaseStream, io.BufferedIOBase, _io._BufferedIOBase, io.IOBase, _io._IOBase, builtins.object

🔧 Methods defined here:

📊 Readonly properties defined here:

📦 Data and other attributes defined here:

🔧 Methods inherited from _io._BufferedIOBase:

🔧 Methods inherited from _io._IOBase:

⚙️ Static methods inherited from _io._IOBase:

📊 Data descriptors inherited from _io._IOBase:

🔧 FUNCTIONS

🔧 compress

compress(data, format=1, check=-1, preset=None, filters=None)

Compress a block of data.

Refer to LZMACompressor's docstring for a description of the optional arguments format, check, preset and filters.

For incremental compression, use an LZMACompressor instead.

🔧 decompress

decompress(data, format=0, memlimit=None, filters=None)

Decompress a block of data.

Refer to LZMADecompressor's docstring for a description of the optional arguments format, check and filters.

For incremental decompression, use an LZMADecompressor instead.

🔧 is_check_supported

is_check_supported(check_id, /)

Test whether the given integrity check is supported.

Always returns True for CHECK_NONE and CHECK_CRC32.

🔧 open

open(filename, mode='rb', *, format=None, check=-1, preset=None, filters=None, encoding=None, errors=None, newline=None)

Open an LZMA-compressed file in binary or text mode.

filename can be either an actual file name (given as a str, bytes, or PathLike object), in which case the named file is opened, or it can be an existing file object to read from or write to.

The mode argument can be "r", "rb" (default), "w", "wb", "x", "xb", "a", or "ab" for binary mode, or "rt", "wt", "xt", or "at" for text mode.

The format, check, preset and filters arguments specify the compression settings, as for LZMACompressor, LZMADecompressor and LZMAFile.

For binary mode, this function is equivalent to the LZMAFile constructor: LZMAFile(filename, mode, ...). In this case, the encoding, errors and newline arguments must not be provided.

For text mode, an LZMAFile object is created, and wrapped in an io.TextIOWrapper instance with the specified encoding, error handling behavior, and line ending(s).

📊 DATA

📁 FILE

/usr/lib/python3.10/lzma.py

lzma
📝 NAME 🚀 Quick Reference 📚 MODULE REFERENCE 📖 DESCRIPTION 📦 CLASSES
🔧 LZMACompressor 🔧 LZMADecompressor ⚠️ LZMAError 📂 LZMAFile
🔧 FUNCTIONS
🔧 compress 🔧 decompress 🔧 is_check_supported 🔧 open
📊 DATA 📁 FILE

Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-01 17:04 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^