Skip to main content

Pure in-memory ZPAQ compression for Python (real pybind11 bindings, prebuilt wheels, no C++ toolchain needed to install).

Project description

zpaq

Pure in-memory ZPAQ compression for Python.

Every other pip install-able ZPAQ package on PyPI either shells out to the zpaq executable (which forces temp files). This package is:

  • A real pybind11 binding around libzpaq (the same library the official zpaq CLI uses), wrapping abstract Reader/Writer adapters that read from and write to bytes objects with no filesystem detour.
  • Distributed as prebuilt wheels for Windows, Linux and macOS across modern Python versions. No C++ toolchain needed.

Usage:

import zpaq

raw = b"hello world " * 1_000
blob = zpaq.compress(raw, level=3)   # bytes -> bytes
assert zpaq.decompress(blob) == raw

Compatibility with the zpaq CLI

zpaq.compress() emits the same on-disk format libzpaq itself writes, and zpaq.decompress() understands archives produced by the zpaq a journaling archiver (it identifies the JIDAC index/hash/info segments, discards them, and strips each data segment's trailing fragment-size footer so the recovered bytes match the original file exactly).

Tested on ten varied real files (1 KB to 25 MB, text/image/csv/jar/png/jpg/svg/exe/binary, compression levels 1-5):

Direction Result
zpaq.compresszpaq.decompress 10 / 10 byte-exact
zpaq.compress → official zpaq x CLI 10 / 10 byte-exact
official zpaq a CLI → zpaq.decompress 10 / 10 byte-exact
import zpaq

# Pipe to the official CLI
with open("out.zpaq", "wb") as f:
    f.write(zpaq.compress(my_bytes, level=3))
# ...later, from any machine with the zpaq executable installed:
#   $ zpaq x out.zpaq

# Read an archive that someone else produced with `zpaq a`
with open("their.zpaq", "rb") as f:
    file_bytes = zpaq.decompress(f.read())

When zpaq.decompress is fed a multi-file archive it returns the concatenated bytes of every file in the order the CLI stored them. A future release will expose a per-segment iterator API so individual files can be addressed by name.

API

Function Description
zpaq.compress(data, level=5) Compress a bytes-like object. level is 0..5 (0 = store, 5 = strongest). Returns bytes.
zpaq.decompress(data) Decompress a bytes-like ZPAQ stream. Returns bytes.
zpaq.Error Raised on any libzpaq failure (corrupt stream, bad header, ...).

Both calls release the GIL while libzpaq runs, so zpaq is friendly to threaded workloads.

License

This package is released under the same terms as the underlying libzpaq sources: public domain. See src/zpaq/vendor/COPYING.


Not affiliated with Matt Mahoney. libzpaq was released into the public domain by its original author; this Python package wraps those sources and is an independent community project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zpaq-0.0.3.tar.gz (100.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zpaq-0.0.3-cp311-cp311-win_amd64.whl (325.6 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file zpaq-0.0.3.tar.gz.

File metadata

  • Download URL: zpaq-0.0.3.tar.gz
  • Upload date:
  • Size: 100.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for zpaq-0.0.3.tar.gz
Algorithm Hash digest
SHA256 9cf031637f023c8623ca1da32143ec4b2a99b6baee279402361b61ee3490df0f
MD5 bd10e17140e57275a5b04d664629c508
BLAKE2b-256 1edae87bc5baefe81b49ba16145c204bd7525af80ecbb51b7ac7bca79c9f59be

See more details on using hashes here.

File details

Details for the file zpaq-0.0.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: zpaq-0.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 325.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for zpaq-0.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0dff91643ca5ad6f5da9ffeeea14aa07739ca657cdc8be1b35c705ffb580d399
MD5 cc152597be1121130ec9eb7d879e3912
BLAKE2b-256 b288cce3f3cc9e7a2857d1843c4d07d44249ebaa82da52567f2ad40833a74c24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page