https://github.com/illagrenan/django-brotli
Django middleware that compresses response using brotli algorithm.
https://github.com/illagrenan/django-brotli
brotli compression compression-algorithm django python
Last synced: 2 months ago
JSON representation
Django middleware that compresses response using brotli algorithm.
- Host: GitHub
- URL: https://github.com/illagrenan/django-brotli
- Owner: illagrenan
- License: mit
- Created: 2016-11-01T13:20:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-01-16T21:51:04.000Z (5 months ago)
- Last Synced: 2025-04-03T01:12:33.998Z (3 months ago)
- Topics: brotli, compression, compression-algorithm, django, python
- Language: Python
- Homepage:
- Size: 362 KB
- Stars: 24
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Django Brotli: *Middleware that compresses response using brotli algorithm*
[](https://opensource.org/licenses/MIT)
[](https://docs.astral.sh/ruff/formatter/)
[](https://pypi.org/project/django-brotli/)
[](https://pypi.org/project/django-brotli/)

[](https://github.com/illagrenan/django-brotli/actions/workflows/development.yml)
[](https://codecov.io/github/illagrenan/django-brotli)* PyPI:
* License: [MIT](https://choosealicense.com/licenses/mit/)## Introduction
This project consists of `BrotliMiddleware` which works the same as Django `GZipMiddleware` ([Docs](https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip)/[Source](https://github.com/django/django/blob/master/django/middleware/gzip.py#L10-L52)). `BrotliMiddleware` will compress content of HTTP response using brotli algorithm (Brotli Compressed Data Format is defined in [RFC 7932](https://www.ietf.org/rfc/rfc7932.txt)).
In November 2016 is brotli supported by Firefox, Chrome, Android Browser and Opera (detailed stats on [caniuse](http://caniuse.com/#search=brotli)). Brotli is applied only when client has sent `Accept-Encoding` header containing `br`.
## Installation
- Supported Python versions are: `">=3.10, <3.14"`.
- Supported Django versions are: `>=4,<6`.```console
poetry add django-brotli@latest
```*or*
```console
pip install --upgrade django-brotli
```Add `django_brotli.middleware.BrotliMiddleware` to `MIDDLEWARE`:
```python
MIDDLEWARE = [
'django_brotli.middleware.BrotliMiddleware',
# ...
]
```## Credits and Resources
- [Brotli on Wikipedia](https://en.wikipedia.org/wiki/Brotli)
- [Brotli compression format repository by Google](https://github.com/google/brotli)## Contributing
1. Clone this repository (`git clone ...`)
2. Install package dependencies: `poetry install --with dev -v`
3. Change some code
4. Run tests: in project root simply execute `pytest`
5. Submit PR :)## License
[The MIT License (MIT)](./LICENSE)