import contextlib
import lzma
import tarfile
with contextlib.closing(lzma.LZMAFile('test.tar.xz')) as xz:
    with tarfile.open(fileobj=xz) as f:
        f.extractall('.')
How to decompress a .xz file which has multiple folders/files inside, in a single go?