Cross-platform Python wrapper for liblhasa (LHA/LZH archives)
Low maintenance activity. Last release 10 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install pylhasapylhasa
pylhasa is a cross-platform Python wrapper for the LHA/LZH archive format. It vendors the liblhasa C sources and builds a CPython extension, producing wheels for Linux, macOS, and Windows.
Install
From PyPI:
pip install pylhasa
Wheels are built for Python 3.9+.
Usage
import pylhasa
archive = pylhasa.open("example.lha")
for entry in archive:
print(entry.raw_path, entry.size)
# Read bytes directly (loads full file into memory)
payload = archive.read("hello.txt")
# Stream contents (incremental reads, avoids large memory usage)
entry = next(iter(archive))
with entry.open() as stream:
chunk = stream.read(1024)
# Extract safely (default)
archive.extractall("out")
archive.close()
API overview
Top-level functions:
pylhasa.open(path): open an archive from a filesystem path.pylhasa.open_bytes(data)/pylhasa.from_bytes(data): open from in-memory bytes.pylhasa.open_fileobj(fileobj, buffering=131072): open from a stream by spooling to a temp file.
Archive behavior:
Archiveis iterable; each item is anEntry.Archive.read(name_or_entry)returns the full bytes of a file entry.Entry.read()returns the full bytes for that entry (same asArchive.read(entry)).Archive.extract(name_or_entry, dest_dir, safe=True, allow_symlinks=False, verify_crc=True)extracts a single entry.Archive.extractall(dest_dir, safe=True, allow_symlinks=False, verify_crc=True)extracts all entries.
Entry behavior:
Entry.open()returns a binary file-like object for streaming decompressed data.Entry.read()loads the full entry into memory in one call.Entry.read()reads the full decompressed bytes into memory.Entry.raw_pathpreserves the original path from the archive;Entry.safe_pathis the sanitized path used for safe extraction.
Examples
See examples/ for runnable scripts:
examples/list_entries.pyexamples/extract_all.py