How can I read a .xz file in Python?

2.9k Views Asked by At

I am downloading files from the web with the ending .xz. It says they are JSONstrean files.

Is there a way to read these files in Python, for example like a CSV file?

1

There are 1 best solutions below

0
Prasun Chakraborty On

Python has a library lzma for Reading and writing compressed files

Here is a simple running code

import lzma
with lzma.open('filename.xz', mode='rt') as file:
    for line in file:
       print(line)