Skip to main content

cendor-contextkit

Treat the context window like a packed suitcase, not a string you concatenate. Declare blocks with priorities and eviction rules; contextkit fits them to a token budget and tells you exactly what it kept, shrank, and dropped.

Every assembled prompt comes with a receipt.

PyPI license · pip install cendor-contextkit

Using an AI coding assistant? npx @cendor/init (TS) / uvx cendor-init (Python) wires it up — or point it at cendor.ai/docs/for-ai-assistants.

from cendor.contextkit import Context, Block

ctx = Context(budget_tokens=8000, model="claude-opus-4-8", reserve_output=1000, order="attention")
ctx.add(Block(system_prompt, priority=10, pin=True, role="system"))
ctx.add(Block(retrieved_docs, priority=5, evict="compress"))        # uses squeeze if installed
ctx.add(Block(messages=chat_history, priority=3, evict="drop_oldest"))  # peels OLDEST turns
ctx.add(Block(user_msg, priority=9, pin=True, role="user"))

messages = ctx.assemble()      # provider-ready, guaranteed within budget — including framing
print(ctx.report())            # the receipt: kept / truncated / dropped + token math
preview = ctx.whatif(budget_tokens=4000)   # same inputs, tighter budget, no commit

Highlights

  • Token-budgeted packing — declare Blocks with priority and pin; assemble() fits them into the budget deterministically. Pinned blocks are never evicted (raises BudgetError if they alone overflow).
  • Per-block eviction — drop_oldest · truncate (keep head/tail, with a …[truncated] marker) · summarize (sync, or async via aassemble()) · compress (via squeeze — reversible: the receipt's BlockDecision.handle.expand() restores the original, and compression is sized against your model) · or any custom EvictionStrategy.
  • Real chat-history — Block(messages=[…]) peels the oldest turns to fit (a sliding window) — never mangling a turn.
  • An honest receipt — report().used == tokens.count(assemble(), model): packing charges the per-message framing providers add, so a "full" prompt never quietly overflows once sent.
  • Attention-aware ordering — order="default" · "attention" (lost-in-the-middle) · "cache" (stable prefix for prompt-cache hits).
  • Provider adapters & multimodal — for_anthropic() / for_gemini() / for_bedrock(); per-image image_tokens (int or resolution-aware callable); whatif(budget) previews; use_compressor() swaps the compression backend.

Inbound — call it before the model call; report() flows onto core's bus, so acttrace records what the model actually saw.

See docs/contextkit.md · CHANGELOG. Part of the Cendor stack — github.com/cendorhq/cendor-libs. Powered by PowerAI Labs. Apache-2.0; provided "as is", without warranty — use at your own risk (LICENSE §7–8).

Metadata

Release files for cendor-contextkit 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cendor-contextkit 1.1.0
File Size Uploaded
cendor_contextkit-1.1.0.tar.gz 29.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cendor-contextkit 1.1.0
File Interpreter ABI Platform
cendor_contextkit-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.0 kB

Release files / cendor_contextkit-1.1.0.tar.gz

Download URL cendor_contextkit-1.1.0.tar.gz
Size 29.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a4aa95d6059fa65ab2983984022739a5f49b0630db6bb0c823111dd218db4113
BLAKE2b-256 checksum
How to use checksums
cbea637fddf49036d951c921c0037dc0a9bbdda1ffe4b7123d71c5d991d9fc4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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 Jul 31, 2026.

Transparency log

Release files / cendor_contextkit-1.1.0-py3-none-any.whl

Download URL cendor_contextkit-1.1.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e17378cdb2647c8c961febea140cc521068319112827193ef3bbcef93f38c1aa
BLAKE2b-256 checksum
How to use checksums
762ea8f25ca6c2bcd42f027f252b0f50adc3fed1eb27f6b44b7b13c28806f777
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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 Jul 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page