Skip to main content

Django Brotli: Middleware that compresses response using brotli algorithm

License: MIT pypi pypi Python version Supported Django
Build Status codecov

Introduction

This project consists of BrotliMiddleware which works the same as Django GZipMiddleware (Docs/Source). BrotliMiddleware will compress content of HTTP response using brotli algorithm (Brotli Compressed Data Format is defined in RFC 7932).

In November 2016 is brotli supported by Firefox, Chrome, Android Browser and Opera (detailed stats on caniuse). Brotli is applied only when client has sent Accept-Encoding header containing br.

Installation

  1. Requirements: Python >=3.11 and Django >=5.2. Install the package:

    uv add django-brotli
    

    or

    poetry add django-brotli@latest
    

    or

    pip install --upgrade django-brotli
    
  2. Add django_brotli.middleware.BrotliMiddleware to MIDDLEWARE:

    MIDDLEWARE = [
        "django_brotli.middleware.BrotliMiddleware",
        # ...
    ]
    

Configuration

Set these environment variables before Django starts; they are read once on import.

Variable Default Values
BROTLI_QUALITY 4 0 (fastest) to 11 (smallest output)
BROTLI_MODE MODE_GENERIC MODE_GENERIC, MODE_TEXT, MODE_FONT

The default quality 4 is about 2× faster than Django's GZipMiddleware and gives about 20% smaller output (#117).

Credits and Resources

Contributing

  1. Clone this repository (git clone ...)
  2. Install package dependencies: uv sync
  3. Change some code
  4. Run linters and tests: uv run task lint coverage
  5. Submit PR :)

License

The MIT License (MIT)

Metadata

Release files for django-brotli 0.5.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 django-brotli 0.5.0
File Size Uploaded Provenance Actions
django_brotli-0.5.0.tar.gz 7.8 kB With provenance Details for django_brotli-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-brotli 0.5.0
File Interpreter ABI Platform Actions
django_brotli-0.5.0-py3-none-any.whl Python 3 none any Details for django_brotli-0.5.0-py3-none-any.whl

Total release size: 13.6 kB

Release files / django_brotli-0.5.0.tar.gz

Download URL django_brotli-0.5.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
776ae4a7549bdd80fa5ed8900efc04e9ecffe66a4f7c26e0a21579c103e12679
BLAKE2b-256 checksum
How to use checksums
3f09ccb8d2e49770118789ccedfdc8ea071db4e0290629593b58e6e3fe1156f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Release files / django_brotli-0.5.0-py3-none-any.whl

Download URL django_brotli-0.5.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4b5fd774b5bf508b9b3126c478a520018f66b91f82b3a28a6a5f2494d5f629c
BLAKE2b-256 checksum
How to use checksums
eef6283388efa0a03692534edaa33ddcea3cd08acee7d38a242b29eb9bda0104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Security for django-brotli 0.5.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_brotli-0.5.0.tar.gz

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 Nov 18, 2026.

Transparency log

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.

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