Skip to main content

Sempress

Semantic compression for tabular data and images using vector quantization

PyPI License Python

Sempress achieves 5-15x better compression than gzip on numeric-heavy datasets by learning per-column codebooks with K-Means vector quantization. String and ID columns are preserved losslessly; precision-critical columns can store exact residuals.

Installation

pip install sempress

Optional extras:

pip install sempress[image]   # PSNR/SSIM metrics (scikit-image, scipy)
pip install sempress[audio]   # Audio compression (librosa, soundfile)
pip install sempress[api]     # FastAPI server (fastapi, uvicorn)
pip install sempress[all]     # Everything

CLI Usage

# Compress CSV to .smp format
sempress encode --in data.csv --out data.smp --lock-cols id,timestamp --k 64

# Decompress back to CSV
sempress decode --in data.smp --out restored.csv

# Evaluate reconstruction quality
sempress eval --original data.csv --recon restored.csv --lock-cols id,timestamp

Options:

  • --lock-cols: Columns preserved losslessly (strings, IDs, timestamps)
  • --residual-cols: Columns with exact error stored (financial, scientific)
  • --k: Codebook size per column (default: 64, range: 16-256)
  • --uncert-thresh: Flag cells with relative error above threshold (default: 0.2)

Python API

from sempress import encode_csv, decode_to_csv
from sempress.table_encoder import EncodeConfig

config = EncodeConfig(
    lock_cols=["id", "timestamp"],
    residual_cols=["amount"],
    k=64,
    uncertainty_thresh=0.2,
)

# Compress
blob = encode_csv("data.csv", config)
with open("data.smp", "wb") as f:
    f.write(blob)

# Decompress
decode_to_csv(blob, "restored.csv")

How It Works

  1. Column analysis - auto-detects numeric vs categorical columns
  2. Learn codebooks - K-Means learns k centroids per numeric column
  3. Encode to indices - replaces values with nearest centroid index (uint16)
  4. Add residuals (optional) - stores exact errors for high-precision columns
  5. Package - msgpack + zstd container (.smp / SEMZ1 format) with schema and metadata

Benchmarks

Tested on 10,000 rows of IoT sensor data (1.4 MB):

Metric Sempress gzip Improvement
Compression Ratio 15.72x 2.48x +533%
Final Size 93 KB 603 KB 84% smaller
Data Fidelity 97.5% 100% (lossless) Configurable

Sempress excels on numeric-heavy data (IoT, ML features, financial). For text-heavy or very small tables, gzip may be simpler.

Git LFS Integration

For automatic compression in Git repositories, see the companion plugin: git-lfs-sempress

Research Paper

sempress.net/paper.pdf

@article{sempress2025,
  title={Sempress: Semantic Compression for Numeric Tabular Data via Learned Vector Quantization},
  author={Anderson, Keaton},
  year={2025},
  url={https://sempress.net}
}

License

MIT License - see LICENSE for details.

Release files for sempress 0.3.2

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

Source distribution (sdist)

Source distribution for sempress 0.3.2
File Size Uploaded
sempress-0.3.2.tar.gz 47.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sempress 0.3.2
File Interpreter ABI Platform
sempress-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 94.4 kB

Release files / sempress-0.3.2.tar.gz

Download URL sempress-0.3.2.tar.gz
Size 47.9 kB
Tags Source
SHA-256 checksum
How to use checksums
45687430476b6cbb6a937bb00755cb4c276f0809a3de10e243baff12670f1aee
BLAKE2b-256 checksum
How to use checksums
2839324b238a562c65c95040cf617971df4a6c0846fa24d3d2e60b3010a549ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / sempress-0.3.2-py3-none-any.whl

Download URL sempress-0.3.2-py3-none-any.whl
Size 46.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3e81fcad00fca9f813b5cfde55b3948cee3bb194c3b77916cb739a25fe0f345
BLAKE2b-256 checksum
How to use checksums
5bd321fbb07e9a840aba17e8a28c8247d8ca101a36020bc30aee2348594db8f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

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