pydoc > lzma

πŸ“› NAME

lzma - Interface to the liblzma compression library.

πŸš€ Quick Reference

Use CaseCommandDescription
Compress byteslzma.compress(data)Compress using default XZ format
Decompress byteslzma.decompress(data)Decompress XZ‑compressed data
Open XZ for readinglzma.open('file.xz', 'rb')Binary read from compressed file
Open XZ for writinglzma.open('file.xz', 'wb')Binary write to compressed file
Incremental compressionc = lzma.LZMACompressor(); c.compress(chunk); c.flush()Compress data in chunks
Incremental decompressiond = lzma.LZMADecompressor(); d.decompress(chunk)Decompress stream progressively
Raw LZMA2 compressionlzma.compress(data, format=lzma.FORMAT_RAW, filters=[{'id': lzma.FILTER_LZMA2}])Compress with custom filter chain
Check integrity supportlzma.is_check_supported(lzma.CHECK_CRC64)Test if a check ID is available

🌐 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

πŸ—œοΈ class 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

πŸ’¨ class LZMADecompressor

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

Create a decompressor object for decompressing data incrementally.

format Specifies the container format of the input stream. If this is FORMAT_AUTO (the default), the decompressor will automatically detect whether the input is FORMAT_XZ or FORMAT_ALONE. Streams created with FORMAT_RAW cannot be autodetected. memlimit Limit the amount of memory used by the decompressor. This will cause decompression to fail if the input cannot be decompressed within the given limit. filters A custom filter chain. This argument is required for FORMAT_RAW, and not accepted with any other format. When provided, this should be a sequence of dicts, each indicating the ID and options for a single filter.

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

Methods

Data descriptors

⚠️ class LZMAError

Call to liblzma failed.

Method resolution order: LZMAError β†’ builtins.Exception β†’ builtins.BaseException β†’ builtins.object

Data descriptors

Methods inherited from Exception / BaseException

Data descriptors inherited from BaseException

πŸ“ class 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

Other attributes

Methods inherited from BufferedIOBase / IOBase

Data descriptors inherited from 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 (str, bytes, or PathLike object) or an existing file object.

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

CHECK_CRC32 = 1
CHECK_CRC64 = 4
CHECK_ID_MAX = 15
CHECK_NONE = 0
CHECK_SHA256 = 10
CHECK_UNKNOWN = 16
FILTER_ARM = 7
FILTER_ARMTHUMB = 8
FILTER_DELTA = 3
FILTER_IA64 = 6
FILTER_LZMA1 = 4611686018427387905
FILTER_LZMA2 = 33
FILTER_POWERPC = 5
FILTER_SPARC = 9
FILTER_X86 = 4
FORMAT_ALONE = 2
FORMAT_AUTO = 0
FORMAT_RAW = 3
FORMAT_XZ = 1
MF_BT2 = 18
MF_BT3 = 19
MF_BT4 = 20
MF_HC3 = 3
MF_HC4 = 4
MODE_FAST = 1
MODE_NORMAL = 2
PRESET_DEFAULT = 6
PRESET_EXTREME = 2147483648
__all__ = ['CHECK_NONE', 'CHECK_CRC32', 'CHECK_CRC64', 'CHECK_SHA256', ...]

πŸ“„ FILE

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

lzma
πŸ“› NAME πŸš€ Quick Reference 🌐 MODULE REFERENCE πŸ“– DESCRIPTION πŸ“¦ CLASSES
πŸ—œοΈ class LZMACompressor πŸ’¨ class LZMADecompressor ⚠️ class LZMAError πŸ“ class LZMAFile
βš™οΈ FUNCTIONS
πŸ—œοΈ compress πŸ’¨ decompress πŸ” is_check_supported πŸ“‚ open
πŸ“Š DATA πŸ“„ FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 11:14 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^