PYPI PACKAGE AUDIT v0.14.0 Gesundes Paket

compache

Passen Sie Prompt-Caching und Kontextkomprimierung an Ihre eigenen Konversationsspuren an.

PyPkgScore compache
Methodik & Kriterien ♥ Donate
770 / 1000
Schnellinstallation
pip install compache
1. Governance
50/200
2. PEP-Metadaten
200/200
3. Sicherheit
200/200
4. Doku & SEO
155/200
5. CI-Engineering
165/200
📣 Prüfung teilen: Teilen Sie diesen Bericht und die Vorschau in der aktuellen Sprache
Advertisement
PYPI-TELEMETRIE

Downloads & Community-Verbreitung

Letzte 30 Tage (ohne Spiegelserver)
Letzte 7 Tage
252
Letzte 30 Tage
252
Gesamt (180 Tage)
252
Metrik / Ökosystem Status / Wert Quelle
Downloads (30d / 180d) — PyPI Stats (without mirrors)
Trusted Publishing (PEP 740) ✓ Verified OIDC PyPI Integrity / Sigstore
Django Packages — djangopackages.org
PyTech / PyPkgScore 770 / 1000 PyPkgScore Engine

Gesundheits- & Engineering-Analyse (5 Säulen)

1. Governance & Community50 / 200 ▾
LICENSE✓ 50 pts
SECURITY.md✕ 0 pts
CONTRIBUTING.md✕ 0 pts
CODE_OF_CONDUCT.md✕ 0 pts
2. PEP-Metadaten & Paketierung200 / 200 ▾
Wheel (.whl)✓ 50 pts
pyproject.toml✓ 50 pts
Project URLs✓ 50 pts
Trove Classifiers✓ 50 pts
3. Sicherheit & Lieferkette200 / 200 ▾
Null CVEs (OSV)✓ 60 pts
Trusted Publishing (OIDC)✓ 50 pts
Snyk / Audit Link✓ 40 pts
HTTPS-Repository✓ 50 pts
4. Dokumentation, SEO & Ökosystem155 / 200 ▾
Strukturierte README✓ 60 pts
Read the Docs✓ 50 pts
Django Packages✕ 0 pts
Webseite / Fachartikel✓ 45 pts
5. Engineering, CI & Qualität165 / 200 ▾
Automatisierte Tests✓ 65 pts
GitHub Actions CI✓ 65 pts
CHANGELOG.md✕ 0 pts
Env & Lockfile (uv/rye/poetry/pdm/hatch)✓ 35 pts
Advertisement
README & DOCS

Offizielle Dokumentation & Nutzungsleitfaden — compache

PyPI Metadata v0.14.0
Vollständige Originaldokumentation anzeigen (Englisches README) ▾

compache

Stop paying for your whole chat history on every message.

Tests Python 3.11+ No dependencies Apache-2.0

compache sits between your chatbot and the model API. It learns from your own conversations which parts of the history still matter and when your users come back, then sends less and caches better. The rest of your application stays as it is.

Billed per 1,000 user messages on Claude Haiku 5.5: $2.68 without compache, $1.45 with. Right answers out of 208: 125 without, 135 with

Get started · Works with · Results · Cost calculator · Docs

Why long chats get expensive

Models have no memory, so your app sends the whole conversation with every message: each question, each answer, each document it ever retrieved. There are two ways to pay less, and they work against each other:

  • Prompt caching makes repeated text cheap, until the user takes a break and the cache expires. On Claude that takes five minutes.
  • Trimming (compaction) sends less text, but rewriting the history throws the cache away, and the model can lose something it needs.

compache is compaction + cache, decided together:

A 26-message chat: the whole history grows to 89k tokens, compache sends at most 25k. It trims on every message where the cache had expired, and pings keep the cache warm through other breaks

  • Trims at the right moment. When the cache has expired, the history has to be paid for in full anyway. That is when compache trims it.
  • Keeps the cache warm. While a user is away for a short break, a tiny request (a ping) keeps the cache alive, if that costs less than losing it. Where your users stay away longer, it asks Claude for its one-hour cache instead.
  • Keeps the rest in reach. Trimmed text leaves a short notice. When the model needs it, it can fetch it back before your app sees the reply.

Get started

pip install compache

1. Record. One line around the client you already have. Your requests and replies do not change.

import compache
from anthropic import Anthropic

client = compache.wrap(Anthropic(), record="compache-record", sample=0.1)

The record holds sizes, times and token usage, never text. For one message in ten, the model is asked afterwards which earlier parts its reply needed, which adds about 5% to the bill while you record. In our runs some 600 messages were enough.

2. Fit. compache prices every candidate setting on your own traffic and prints what you would save, before anything in your app changes.

compache fit compache-record --model claude-haiku-5-5

3. Apply. Same line, with the result.

client = compache.wrap(Anthropic(), "policy.json")

That is all. There are no thresholds to tune.

compache demo -o policy.json
Fitted on 4 sample threads, 71 turns (71 labelled) for claude-sonnet-5-5.

Keep questions from the last 4 turns, answers from the last 9 turns and retrieved text from the last turn.
Send up to 1 keep-warm ping while a user is away.
82% of what the labelled turns need from earlier turns stays in view. The rest is fetched back, and that call is in the cost.
$16.10 per 1,000 turns against $50.25 keeping everything: 68% less.
Caching alone, at its best, would cost $18.66.

Wrote policy.json

In a clone of this repository, python examples/quickstart/apply.py then plays one of those chats, the one in the figure above, message by message.

compache pull langfuse -o threads.jsonl.gz      # or: mlflow, otel. Your own chat log works as it is
compache fit threads.jsonl.gz --labels labels.jsonl --model claude-haiku-5-5

Labels say, for a sample of messages, which earlier parts were needed. A coding-agent skill writes them. Without labels compache keeps the whole history and tunes the pings. Guide

Works with

Your stack What you add
OpenAI, Anthropic and Google GenAI SDKs, sync, async and streaming compache.wrap(client, "policy.json")
LangChain and LangGraph on ChatOpenAI compache.langchain.clients(...) and middleware()
OpenAI Agents SDK, Pydantic AI, LlamaIndex, Agno, AutoGen, Strands, Haystack, Langfuse's OpenAI drop-in The wrapped client, one line each
LiteLLM compache.litellm.install(...), or a callback in your LiteLLM proxy
Hermes context.engine: compache
Anything with a base URL: the Vercel AI SDK, OpenClaw and other agent harnesses compache proxy --policy policy.json
Your own prompt assembly policy.session(thread_id)

Everything runs in your own process and talks only to your model provider. No state is kept outside the process, so trimming works in serverless functions and across deploys. Keep-warm pings need a process that stays up; without one, fit with ping_counts=(0,). A request the provider refuses after compache changed it is sent again as your app wrote it. All integrations

Why learn it from your data?

Because every chatbot needs a different answer. Three workloads, three settings, each priced by the provider's cache rules on conversations compache had not seen, against sending everything:

Chatbot What compache learned Cost
Chat with documents (DocChat) Questions and answers matter for long. Retrieved text is rarely needed after one message, so it goes 43% to 89% less
Long personal chats (BEAM) What the user said matters. Earlier replies of the assistant can go 57% to 91% less
Data analysis (LongDS) Almost every step builds on earlier ones. Keep nearly everything, and time the pings 0% to 32% less

On DocChat that is against Claude's 5-minute cache, and against its 1-hour cache 30% to 79%. How long users stay away matters as much. The same document chats, with three kinds of users:

The same chats with users who return after 30 seconds, 4 minutes and 30 minutes: sending everything costs 1.8, 5.9 and 8.9 times what compache's setting costs

A fixed rule such as "keep the last 20 messages" or "summarize at 75% of the window" is one setting for all of these.

Results

Measured on Cost
Claude Haiku 5.5, against the 5-minute cache Live calls, billed, four integrations 42% to 49% less
Claude Haiku 5.5, against the 1-hour cache Live calls, billed, short chats 18% less
GPT-6 Luna, against the 30-minute cache Live calls, billed, one integration 2% to 5% less
Claude Sonnet 5.5, against the 5-minute cache DocChat, modeled cost 43% to 89% less
Claude Sonnet 5.5, against the 1-hour cache DocChat, modeled cost 30% to 79% less

It pays off most in long chats with a lot of retrieved or tool text, where users pause longer than the cache lasts. It pays off least in short chats and where the cache outlasts the breaks: on GPT-6 Luna these users were always back in time, so there was little to save. If your app already uses Claude's 1-hour cache, the 1-hour row is yours: its writes cost more and its entries last longer, so there is less left to save, most of all in short chats. The long cache

Answers hold up. In every measurement, the number of right answers with and without compache differs by no more than chance. On GPT-6 Luna it was slightly lower, on too few messages to call. Live runs · All benchmarks

What would you save? Put your numbers in the cost calculator, or drop a chat log or a policy.json on it: it is read in your browser and sent nowhere. It compares with your own rules, other tools' defaults or what you pay now.

Next to what you already use

You use compache adds
Prompt caching, the 1-hour cache included What to do when the cache is about to expire, and what to drop once it has
Keep the last N messages, or summarize at a threshold N learned per kind of text, cuts timed to the cache, and trimmed text the model can fetch back
OpenClaw or provider compaction at fixed thresholds A setting fitted to your traffic. Modeled on Claude Sonnet 5.5, 48% to 54% cheaper than OpenClaw's defaults
A cache tool such as caching.ai, or one-hour cache entries Sending less. Modeled on document chats, 30% to 70% cheaper than the cheapest cache setting alone
Headroom or OptScale Kompressor They shrink single tool results, compache decides which parts stay and when the cache is kept warm. Live on document chats, 36% and 26% cheaper with the answers of the whole history

Guide · Integrations · How it works · Other tools compared · Calculator · Issues · Apache-2.0