Back to directory

leanctx

A Python library that acts as a drop-in replacement for LLM provider clients such as OpenAI, Anthropic or Gemini, compressing prompts to cut token costs while treating code and structured data as untouchable.

leanctx

leanctx is a drop-in prompt compression library for production LLM applications, used by swapping the import for a provider's own client, such as OpenAI's, for leanctx's version so requests are compressed automatically without other code changes.

It classifies each part of a prompt by how much distortion it can tolerate: code, stack traces and structured tool-call data are kept verbatim; documentation, retrieved passages, logs and prior turns are compressed on-device with LLMLingua-2; and low-confidence prose can optionally be compressed with a further LLM call. On the LongBench v2 benchmark, layered on top of an existing compressor, it removes an additional 18.7% of tokens on average, rising to 36.7% on prose-heavy traffic, at a cost of 1.8 percentage points of accuracy.

It is open source, MIT licensed, and runs locally, so prompts and user data stay on the caller's own infrastructure by default.

More in Libraries

See all 292
  • OpenDecision

    deepanwadhwa.github.io

    An open-source Python package that answers typed questions about application state or documents using a local natural-language-inference model, returning structured choice, score, yes/no or evidence-relation values instead of free text.

  • TradeCanvas

    bonguynvan.github.io

    A zero-dependency canvas charting engine for building TradingView-style trading charts in JavaScript, with 66 technical indicators, 24 drawing tools, 17 chart types, and real-time streaming.

  • 3d retro graphics

    3d-retro.com

    A free, CC0-licensed library of copy-paste retro 3D and demoscene graphics effects, such as plasma, raytracing, and voxel terrain, runnable as WebGL 1 or plain 2D canvas.