ContextClip (Python)
Part of LoopEngine — a runtime for defining and running AI agents through a transparent ReAct loop — handling context-window budget tracking with staged recovery. Works standalone too, no dependency on LoopEngine itself.
Ported line-for-line from the TypeScript implementation. See the root README for the pitch, the prior-art table, and the scope decisions — this file only covers what's specific to running the Python code.
Install
pip install -e ".[dev]"
Quickstart
PYTHONPATH=src python3 examples/quickstart.py
from contextclip import ContextClipper
clipper = ContextClipper(budget_tokens=200, tail_messages=2)
status = clipper.check(messages)
if status.action == "over_hard_limit":
result = await clipper.recover(messages)
# result.action is "drained" or "summarized" — result.messages never
# touches the last `tail_messages` of the original list.
Test
pytest
Status
Budget tracking, threshold checks, and staged drain-then-summarize
recovery with tail preservation are real and tested. Published as
contextclip on PyPI.
Metadata
Release files for contextclip 0.0.3
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 |
|---|---|---|---|---|
| contextclip-0.0.3.tar.gz | 5.4 kB | Without provenance | Details for contextclip-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| contextclip-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for contextclip-0.0.3-py3-none-any.whl |
Total release size: 11.3 kB
Release files / contextclip-0.0.3.tar.gz
| Download URL | contextclip-0.0.3.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
475ec16d71e0bd888b862d86514054be986dcd449974b003222b689fa3876dfa
|
|
BLAKE2b-256 checksum How to use checksums |
735e055313f8cee7383f34f448f3714df67b3dee797f43a221cd38e2ee6e350d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Release files / contextclip-0.0.3-py3-none-any.whl
| Download URL | contextclip-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd5bc640ea11ce34a37084aa3f9f03f47c33daae867e8157185a21e7f924bf1b
|
|
BLAKE2b-256 checksum How to use checksums |
45c116e918125cec96d7ce83742624f658634860dda75feff014a7bb509528a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Security for contextclip 0.0.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.