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) or ships only an sdist (which forces every user to have a working C++ toolchain). This package is both:

  • 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. Installing it never compiles anything.

On Windows, the wheel statically links the C and C++ runtimes so users do not need to install any "Visual C++ Redistributable" package - if Python runs, zpaq works.

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.

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.1.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.1-cp311-cp311-win_amd64.whl (325.7 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

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

File metadata

  • Download URL: zpaq-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 5b86b7cfb3c9bcf88e404f917a88c878c18abc12c207f02d29190544ba71d1f9
MD5 61420e5bd3f83a83faed8f8a7be99513
BLAKE2b-256 e644c90a9d404f0856ac233d7d9bc19c564c40d60a49cddb0ab3857add2b28a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zpaq-0.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 325.7 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6ed33eee82afaedf8984f5a9f6b5ee3b615eeb35466e843ef97fb61da3687dad
MD5 0fc460d16b934736d48d48cc4a9a15be
BLAKE2b-256 2d89024f867895167df547e6360a990bee43bef288736ddb5ee73e9f87caa6f6

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