ZYVOPMulti-Platform Sync
SeriesAI NewsWhy ZyVOPJoin Discord
LoginGet Started
ZYVOPMulti-Platform Sync

The Developer Publishing Hub. Write once, publish everywhere, and make your work citation-ready with built-in SEO, AEO, and GEO discovery support. Zero reader paywalls.

Content

  • Categories
  • Tags
  • Badges
  • Leaderboard
  • Write Article
  • Newsletter

Company

  • About Us
  • Why ZyVOP
  • Developer API & CLI
  • Write for Us
  • Contact

Connect

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DMCA Policy
  • Code of Conduct

© 2026 ZyVOP. Developer Publishing Hub.

Zero paywalls · Full content ownership
All systems operational
HomeCase StudiesA Simple Look at TokPress: A Compressor That Uses an LLM's Tokenizer
Case Studies

A Simple Look at TokPress: A Compressor That Uses an LLM's Tokenizer

Lê Đức Minh
Lê Đức Minh
AI Engineer
September 6, 2026
2 min read
A Simple Look at TokPress: A Compressor That Uses an LLM's Tokenizer
Article

If you've ever compressed a bunch of small JSON log lines, you've probably noticed something annoying: gzip often makes them bigger, not smaller. A 200-byte log line has so little content that the compressor spends more bytes on its own bookkeeping than it saves.

TokPress is a tiny weekend project that tries a different trick: instead of compressing raw bytes, it first runs the text through the same tokenizer that OpenAI's models use (o200k_base), then compresses the tokens.

That's the whole idea. An LLM tokenizer has already learned which pieces of text are common — words, punctuation, code patterns. So the compressor gets a much better alphabet to work with for free.

What it actually does

Three simple steps:

  1. Tokenize — turn the input into token ids using o200k_base.

  2. Compress the tokens — run a simple LZ77 pass over the token ids.

  3. Entropy-code — finish with rANS, an efficient entropy coder.

The result is a .tokz file that decompresses back to the exact original bytes — even binary data, since the tokenizer works on bytes, not just text.

import tokpress

compressed = tokpress.compress(payload)
original = tokpress.decompress(compressed)   # byte-exact

The trick that makes it useful: a shared dictionary

The real win comes when you have many records that look the same — log lines, API responses, telemetry. TokPress can train a small dictionary on a sample of your records, then every future record compresses against it:

tokpress train-dict mydict.tokdict samples.jsonl
tokpress compress new_record.json --dict mydict.tokdict -o new_record.tokz

With a trained dictionary, structured-log records went from a ratio of 0.800 to 0.2565 — about 3× smaller. And that's on records the dictionary had never seen.

There's an even simpler mode that needs no training at all: compress many records together as one stream, and the model learns as it goes:

packed = tokpress.compress_many(records)
records = tokpress.decompress_many(packed)

On 150 schema-similar JSON records, per-record compression summed to ratio 1.19 — the data literally grew. As one stream, it hit 0.0875. Same bytes, one header instead of 150.

Where it stands (honestly)

  • On prose it beats gzip and ties/beats zstd on some files (a 152KB prose file: 0.298 vs zstd's 0.324).

  • It still loses to zstd's trained dictionary by about 1.3×. zstd has had years of polish on dictionary training; this is a weekend project.

  • It's pure Python, so it's slow to compress. Decompression is fast (thousands of records/sec); compression is not.

  • Tokenization isn't magic. The tokenizer just reshapes the data; the real savings come from the entropy coding and the trained dictionary.

Try it

git clone https://github.com/LakoreAI/tokpress
cd tokpress && pip install -e .
python -c "import tokpress; print(len(tokpress.compress(b'{\"a\": 1}')))"

It's ~2900 lines, has 93 tests, and comes with an honest benchmark script. If you have a folder of repetitive logs or JSON, that's exactly the case it was built for.

Comments (0)

Login to post a comment.

Lê Đức Minh
Lê Đức Minh

AI Engineer

Just Another Dev Guy

Subscribe to Lê Đức Minh's Newsletter

More from Lê Đức Minh

View profile

A Simple Look at TokPress: A Compressor That Uses an LLM's Tokenizer

TokPress compresses tiny JSON log lines by tokenizing with OpenAI's o200k_base tokenizer, then applying LZ77 and rANS for smaller files.

2 minSep 1

Fun Project: I Built a Compressor That Thinks in Tokens

Field notes from a weekend spent teaching an entropy coder to speak LLM. LLMs spent billions of dollars learning the best subword dictionary that has ever exist...

10 minSep 1

Agent harness or agent framework?

In July I wrote Prompt, Context, Harness, Loop, which split an agent into four parts and argued that the harness — the thing that owns the loop and decides what...

6 minAug 17

Five ways to invalidate your prompt cache

Part 2 of 2 on prompt caching. Part 1 covered the economics. Part 1 established the prize: caching cut an 80-turn agent session from $54.08 to $6.91 in my cost ...

9 minAug 17

Why your coding agent's bill grows faster than the chat

Part 1 of 2 on prompt caching. I got curious about a number I had never actually checked: what does a long session with a coding agent really cost, and does the...

8 minAug 17