Integration guide

Django compression integration

Django powers many production AI applications. Add SuperCompress as a Django middleware or view decorator.

By Arjun Shah - Creator of SuperCompress - Updated 2026-07-03

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.

Try it yourself

Paste your long prompt into the playground, ask a question, and see what SuperCompress keeps and removes. Free, no signup needed.

Open the Playground Embed the badge