Integration guide
Django compression integration
Django powers many production AI applications. Add SuperCompress as a Django middleware or view decorator.
Django middleware
# middleware.py
from supercompress import Compressor
comp = Compressor()
class PromptCompressionMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if request.path == "/api/llm/" and request.method == "POST":
data = json.loads(request.body)
if "context" in data and "query" in data:
result = comp.compress(data["context"], data["query"])
data["context"] = result.compressed_text
request._body = json.dumps(data).encode()
return self.get_response(request)
Frequently asked questions
Does it work with Django REST Framework?
Yes. Apply the middleware or use a DRF mixin for view-level compression.
Can I use it with Django Channels?
Yes. Compress messages in the consumer before sending to the LLM.
Build with less context
Put compression in front of your next LLM call.
Use the hosted API or run SuperCompress locally. Keep the evidence, drop the token waste, and measure the savings before it reaches your model.