TerseLib

An open-source, pure-Python implementation of the z/OS TERSE compression format (AMATERSE / TRSMAIN), supporting the PACK (LZW) and SPACK (LZMW) methods, host and native containers, fixed and variable record formats, and text (EBCDIC ⇄ ASCII) or binary rendering with selectable code pages.

Files compressed with TerseLib unpack with AMATERSE on z/OS, and data sets tersed on the mainframe decompress byte-identically here.

Quick start

import terselib

blob = terselib.compress(b"HELLO\nWORLD\n", text=True)
result = terselib.decompress(blob)          # auto-detects text/binary
assert result.data == b"HELLO\nWORLD\n"

Command line:

$ terse report.txt          # compress (SPACK, text, variable records)
$ unterse DATA.TRS          # decompress with content auto-detection
$ unterse -i DATA.TRS       # inspect the header

Indices and tables