from shutil import copyfileobj
with open('bigInputfile.txt', 'rb') as input:
    with bz2.BZ2File('bigInputfile.txt.bz2', 'wb', compresslevel=9) as output:
        pass
Сжатие больших файлов с помощью python