Skip to main content

simple-compression

simple-compression is a small Python library that implements classic byte-oriented compression algorithms with an explicit and composable API.

The library is designed to operate directly on bytearray data and provides both manual and automatic compression pipelines. All encoded outputs are self-describing and can be decoded without external metadata.

Current version: v0.2.0


Scope and goals

This project focuses on:

  • Correct, deterministic implementations of classic compression algorithms
  • Explicit encoding formats that are easy to inspect and reason about
  • A simple API for chaining multiple compression stages
  • Safe and strict decoding

This library does not attempt to compete with production compressors in performance. It is intended for correctness, clarity, and control. BECAUSE OF PYTHON OVERHEAD THIS IS VERY SLOW AND NOT PRACTICAL FOR PRODUCTION USE AS OF RIGHT NOW THIS LIBRARY IS BEST DESIGNED FOR LEARNING ABOUT COMPRESSION EVENTUALLY IT WILL BE REWRITTEN IN C AND OPTIMIZED FOR PERFORMANCE


Implemented algorithms

  • Run-Length Encoding (RLE)
  • LZ77
  • Huffman

Each algorithm has a fully defined binary format and a strict decoder.


Installation

pip install simple-compression

Basic Usage

Both of these features are expected to improve in effectiveness with more testing and tuning as well as the future implementation of a Huffman Algorithm The first usage uses the auto=True argument does a quick pass on the data to gather metrics to automatically select the algorithms and their sequence. The second usage passes the algorithm name as arguments to manually select algorithms and determine their sequence.

from simple_compression.compression import SimpleCompression

compress = SimpleCompression()

data = bytearray(b"AAAAAABBBBBCCDSADDDDDSSSCVZCSSSSWEEEFWEWAFZCVAGQWTQL")

encoded = compress.encode(data, auto=True)
decoded = compress.decode(encoded)

encoded = compress.encode(data, sequence=["RLE", "LZ77"])
decoded = compress.decode(encoded)

The decoder reads header tokens embedded at the start of the bitstream to determine which algorithms were applied and in which order. This allows for a really robust decoder which when combined with the spec documentation for each algorithm can be helpful in implementing decoders in other languages.


Algorithm Formatting

Detailed binary formats for each algorithm are documented below. RLE Format LZ77 Format HUFFMAN Format


Road Map

Currently the library is functional. It has a composable pipeline of basic compression algorithms. The probe for the auto=True argument has been redesigned to be more tunable and collect more metrics. In testing it does better at avoiding using algorithms when the data doesn't fit their use case. The next part of development will be focused on rewritting the library in C so it can be usable outside of an educational setting.


License

MIT

Metadata

Release files for simple-compression 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-compression 0.2.0
File Size Uploaded Provenance Actions
simple_compression-0.2.0.tar.gz 10.5 kB Without provenance Details for simple_compression-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-compression 0.2.0
File Interpreter ABI Platform Actions
simple_compression-0.2.0-py3-none-any.whl Python 3 none any Details for simple_compression-0.2.0-py3-none-any.whl

Total release size: 20.6 kB

Release files / simple_compression-0.2.0.tar.gz

Download URL simple_compression-0.2.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c99f255a52975f176e2ed9fe9d1336653d50fc306e2c5620a33043c8b8b5bc86
BLAKE2b-256 checksum
How to use checksums
00c34f623bf8f6561dfc0e9eec11c799e1cda6d471c0c1a58454ade337f7617d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / simple_compression-0.2.0-py3-none-any.whl

Download URL simple_compression-0.2.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ddfe3c245af1c059636176a9333446c6f9c29e0f4c238b2e6868b0cc0c10660
BLAKE2b-256 checksum
How to use checksums
381e144c9656c6bb06498c77e851a4f5dd55ceb42076d368a79d265ec36387ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for simple-compression 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page