Python 3.3+lzmaterm
lzma.LZMAFile
files
A file object for reading and writing .xz and .lzma files in binary mode.
Syntax
f = lzma.LZMAFile(filename=None, mode='r', *, format=None, check=-1, preset=None, filters=None)
Bytes only: text modes come from lzma.open(). Writing creates an .xz container by default; FORMAT_ALONE is needed only for legacy .lzma files. Reading joins several streams written with mode 'a'. Seeking backwards is emulated by decompressing from the start and is very slow on large files.
Examples
import lzma
with lzma.LZMAFile('data.xz', 'w') as f:
f.write(b'0123456789')
with lzma.LZMAFile('data.xz') as f:
f.seek(5)
print(f.read()) # → b'56789'
f.seek(0)
print(f.read(3)) # → b'012'
See also
Open in the full glossarydocs.python.orgReport an inaccuracy