Skip to main content

Quantum-Inspired Pattern-Aware Compression (QPAC) — Hybrid entropy-aware compression inspired by quantum entropy and LZ4.

Project description

QPAC: Quantum-Inspired Pattern-Aware Compression

PyPI
License: MIT

QPAC (Quantum-Inspired Pattern-Aware Compression) is a Python library for hybrid entropy-aware compression of data. Inspired by LZ4, it supports multiple compression strategies and can adaptively choose the best method for each block of data.


Features

  • Hybrid Compression: Automatically selects between raw, RLE, dictionary, delta, and hybrid strategies.
  • Entropy-Guided: Compression decisions are guided by Shannon entropy to maximize efficiency.
  • Fast and Lightweight: Designed for small blocks (e.g., IoT or memory-constrained environments).
  • Reversible: Supports both compression and decompression for data integrity.
  • Extensible: Easily add custom compression strategies.

Installation

From PyPI (Test)

pip install -i https://test.pypi.org/simple qpac

From PyPI (Production)

pip install qpac

Usage

import qpac
from qpac import compress_block, decompress_block, CompressedBlock

# Sample data
data = bytearray([1,1,1,2,2,3,3,3,4,5,6,7,8])

# Compress
cb: CompressedBlock = compress_block(data)
print(f"Original size: {cb.original_size}")
print(f"Used strategy: {cb.strategy}, compressed size: {cb.compressed_size}")

# Decompress
decompressed = decompress_block(cb)
print(f"Roundtrip ok: {decompressed == data}")

API Reference

compress_block(block: bytes) -> CompressedBlock

Compresses a block of data using the most appropriate strategy based on entropy and patterns.

decompress_block(cb: CompressedBlock) -> bytes

Reverses the compression and returns the original data.

CompressedBlock

Represents a compressed block with the following attributes:

  • strategy: Compression strategy used
  • original_size: Original block size
  • compressed_size: Compressed size
  • data: Compressed byte array

Entropy

calculate_entropy(data: bytes) -> float

Calculates the Shannon entropy of a data block.


Compression Strategies

Strategy Description
STRATEGY_RAW No compression; stores original data
STRATEGY_RLE Run-length encoding for repeated patterns
STRATEGY_DICT Dictionary-based compression
STRATEGY_DELTA Delta encoding for numerical sequences
STRATEGY_HYBRID Adaptive combination based on entropy

License

This project is licensed under the MIT License © Soumyapriya Goswami.
For full license details, see the LICENSE file.


References


Contact

Soumyapriya Goswami
📧 Email: email@Soumyapriya.com
💻 Project Repository: GitHub

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

qpac-0.2.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

qpac-0.2.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file qpac-0.2.1.tar.gz.

File metadata

  • Download URL: qpac-0.2.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for qpac-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0c33b0b740b2d028a9a700c14e7dab7bef2d3f80dcdf3897f039b7cc18d866ca
MD5 4910e31331ac9c3fe0717b2a84587f22
BLAKE2b-256 535e0958a577db637e66f19bdb403519694334fe4b4606ca7fcba75bb2aa0dfc

See more details on using hashes here.

File details

Details for the file qpac-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: qpac-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for qpac-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 077de71316a01d13b3fe8e899575837a1804ea4cd409619fbd0b788f323b4961
MD5 9ecca3e18492038974fc907df3d1cde2
BLAKE2b-256 6b5e26264011ac20f3f32bf4e3e70610134bc1c3a655ec6bf9daf492388efddc

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