delbina
A context-compression layer that sits in front of existing LLMs to cut the token cost of long chats.
Every chat turn re-sends the whole history, so total token cost grows roughly quadratically with chat length. delbina measures that cost and compresses the history before it reaches the model.
Status: alpha (0.x). Token-cost measurement and simple strategies work. Answer-quality evaluation is not built yet, so savings numbers say nothing about whether the model still answers correctly. The API may change.
Install
pip install delbina
On first use, tiktoken downloads its encoding file, so the first run needs network access.
Quick start
from delbina import cost, full, last_n, rolling_summary
turns = ["user: ...", "assistant: ...", "user: ...", "assistant: ..."]
print(cost(turns, full)) # tokens if full history is re-sent every turn
print(cost(turns, last_n(4))) # tokens if only the last 4 turns are sent
context = rolling_summary(keep=2)(turns) # what you would actually send
With a local model (Ollama)
from delbina import ollama_summarizer, rolling_summary
strategy = rolling_summary(keep=4, summarize=ollama_summarizer("qwen2.5:1.5b"))
Requires a running Ollama server. No extra Python dependencies.
CLI
delbina bench chat.json # compare strategies
delbina bench chat.json --ollama qwen2.5:1.5b # use a local model for summaries
chat.json format: {"turns": ["...", "..."]}
Strategies
| Strategy | What is sent each turn |
|---|---|
full |
the whole history (baseline) |
last_n(n) |
the last n turns |
head_tail(h, t) |
the first h turns (task setup) + the last t turns |
rolling_summary(keep, summarize) |
a summary of older turns + the last keep turns |
Note: cost() counts tokens sent to the main model. It does not yet count the tokens spent by the summarizer itself.
Development
python -m venv .venv
pip install -e ".[dev]"
pytest -q
License
Apache-2.0
Metadata
Release files for delbina 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| delbina-0.1.0.tar.gz | 9.9 kB | With provenance | Details for delbina-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| delbina-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for delbina-0.1.0-py3-none-any.whl |
Total release size: 20.1 kB
Release files / delbina-0.1.0.tar.gz
| Download URL | delbina-0.1.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2270bf6daa4420143d65d51abed05f6a9ce982fb5572e372f51b1de8ac3e329
|
|
BLAKE2b-256 checksum How to use checksums |
73d574fbcb4f5dd897ac486a281e9c5c246f2e9ad30e221a4d441b75bf5df26e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / delbina-0.1.0-py3-none-any.whl
| Download URL | delbina-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1dfd4bcda211f7b816a29153b975c524ed01a77dd4db7dd5548dabb778898d4d
|
|
BLAKE2b-256 checksum How to use checksums |
b0d98920e88074be1d5c4657c86ad3e11528c411eaaaa5d0018abbfdc02df5e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for delbina 0.1.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for delbina-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA 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.