Skip to main content

Independent Python implementation of the SpreadsheetLLM SheetCompressor encoding for token-efficient LLM workflows.

Project description

sheet-compressor (Python)

Python port of the SheetCompressor encoding from the SpreadsheetLLM paper. Pure core with zero required dependencies; conforms to the shared golden corpus in fixtures/corpus/. See spec/SPEC.md for the language-neutral contract.

from sheet_compressor import compress

grid = {
    "rows": [
        ["Name", "Qty", "Price"],
        ["Apple", "3", "1.50"],
        ["", "", ""],
        ["Pear", "5", "0.30"],
    ],
    "origin": {"row": 1, "col": 1},
}
result = compress(grid)
print(result["encodings"]["anchor"]["string"])

Real tokenizer (optional)

Install with pip install sheet-compressor[tokenizer] and pass a tiktoken-backed counter to compress:

from sheet_compressor import compress, create_token_counter

result = compress(grid, {"tokenCounter": create_token_counter()})

create_token_counter defaults to o200k_base (GPT-4o / GPT-5 family); pass encoding="cl100k_base" for the GPT-3.5 / GPT-4 family. It raises a clear error if tiktoken is not installed.

Optional .xlsx adapter

Install with pip install sheet-compressor[xlsx] and read a workbook into a Grid via openpyxl:

from sheet_compressor import compress
from sheet_compressor.adapters.xlsx import read_sheet

grid = read_sheet("workbook.xlsx")            # first sheet
grid = read_sheet("workbook.xlsx", {"sheet": "Q3"})  # by name
grid = read_sheet("workbook.xlsx", {"sheet": 1})     # by 0-indexed position
result = compress(grid)

read_sheet accepts a file path, raw bytes, or any binary file-like object. It raises a clear ImportError if openpyxl is not installed. The pure core keeps working without it — build the Grid yourself and pass it to compress() directly.

Conformance

python3 -m unittest discover -s tests

The conformance suite walks every fixture under fixtures/corpus/ and asserts byte-equal output against the goldens — the same shape as the TypeScript reference's conformance test.

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

sheet_compressor-0.1.0.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

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

sheet_compressor-0.1.0-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file sheet_compressor-0.1.0.tar.gz.

File metadata

  • Download URL: sheet_compressor-0.1.0.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sheet_compressor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9500cdff453b5aacc08ce92ef39a639bab64faa4587556127b2068f533a13f5b
MD5 c95e113bd73132fd7f3f6d3ae334311e
BLAKE2b-256 dfd9aeac1f4d91aea150051d94907b0bc35c91dd0b2a3b9536bd5944afb3d1cb

See more details on using hashes here.

File details

Details for the file sheet_compressor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sheet_compressor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d6d1bd2f7d61d7efce636ce30355172ee8a529d02d66539bc1b211735b1eebf
MD5 a4b78b361cdc2a5684b3db89709d975e
BLAKE2b-256 dc14bb3492cbd4e62b14e9ee2f1072d7055e242dbd808e487417a68ce5f211cf

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