All Projects → friedelwolff → Django Compression Middleware

friedelwolff / Django Compression Middleware

Licence: mpl-2.0
Django middleware to compress responses using several algorithms.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Compression Middleware

Connect Gzip Static
connect middleware for statically compressed files
Stars: ✭ 39 (+69.57%)
Mutual labels:  middleware, gzip, brotli
Turbobench
Compression Benchmark
Stars: ✭ 211 (+817.39%)
Mutual labels:  zstd, gzip, brotli
Aspnetcore Request Decompression
HTTP request decompression middleware for ASP.NET Core
Stars: ✭ 51 (+121.74%)
Mutual labels:  middleware, gzip, brotli
EasyCompressor
⚡ A compression library that implements many compression algorithms such as LZ4, Zstd, LZMA, Snappy, Brotli, GZip, and Deflate. It helps you to improve performance by reducing Memory Usage and Network Traffic for caching.
Stars: ✭ 167 (+626.09%)
Mutual labels:  gzip, brotli, zstd
pyrus-cramjam
Thin Python wrapper to de/compression algorithms in Rust - lightweight & no dependencies
Stars: ✭ 40 (+73.91%)
Mutual labels:  gzip, brotli, zstd
restio
HTTP Client for Dart inspired by OkHttp
Stars: ✭ 46 (+100%)
Mutual labels:  gzip, brotli
lambdafs
Efficient (de)compression package for AWS Lambda
Stars: ✭ 24 (+4.35%)
Mutual labels:  gzip, brotli
gzipped
Replacement for golang http.FileServer which supports precompressed static assets.
Stars: ✭ 86 (+273.91%)
Mutual labels:  gzip, brotli
zstdmt
Multithreading Library for Brotli, Lizard, LZ4, LZ5, Snappy and Zstandard
Stars: ✭ 107 (+365.22%)
Mutual labels:  brotli, zstd
Gzip
💾 Golang gzip middleware for Gin and net/http | Golang gzip中间件,支持Gin和net/http,开箱即用同时可定制
Stars: ✭ 113 (+391.3%)
Mutual labels:  middleware, gzip
bundle
An online tool to quickly bundle & minify your projects, while viewing the compressed gzip/brotli bundle size, all running locally on your browser.
Stars: ✭ 475 (+1965.22%)
Mutual labels:  gzip, brotli
ratarmount
Random Access Read-Only Tar Mount
Stars: ✭ 217 (+843.48%)
Mutual labels:  gzip, zstd
restish
Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
Stars: ✭ 453 (+1869.57%)
Mutual labels:  gzip, brotli
Compression
Node.js compression middleware
Stars: ✭ 2,506 (+10795.65%)
Mutual labels:  middleware, gzip
precompress
Generate pre-compressed .gz and .br files for static web servers
Stars: ✭ 27 (+17.39%)
Mutual labels:  gzip, brotli
Everbug
Django debug tool for browser
Stars: ✭ 114 (+395.65%)
Mutual labels:  middleware, django
restler
Restler is a beautiful and powerful Android app for quickly testing REST API anywhere and anytime.
Stars: ✭ 120 (+421.74%)
Mutual labels:  gzip, brotli
Archiver
Easily create & extract archives, and compress & decompress files of various formats
Stars: ✭ 3,373 (+14565.22%)
Mutual labels:  gzip, brotli
Lizard
Lizard (formerly LZ5) is an efficient compressor with very fast decompression. It achieves compression ratio that is comparable to zip/zlib and zstd/brotli (at low and medium compression levels) at decompression speed of 1000 MB/s and faster.
Stars: ✭ 408 (+1673.91%)
Mutual labels:  zstd, brotli
Django Channels React Multiplayer
turn based strategy game using django channels, redux, and react hooks
Stars: ✭ 52 (+126.09%)
Mutual labels:  middleware, django

=========================================================================== Django Compression Middleware

This middleware implements compressed content encoding for HTTP. It is similar to Django's GZipMiddleware (documentation_), but additionally supports other compression methods. It is meant to be a drop-in replacement for Django's GZipMiddleware. Its documentation — including security warnings — therefore apply here as well.

The middleware is focussed on the task of compressing typical Django responses such as HTML, JSON, etc. Both normal (bulk) and streaming responses are supported. For static file compression, have a look at other projects such as WhiteNoise_.

Zstandard is a new method for compression with little client support so far. Most browsers now support Brotli compression (check support status on Can I use... Brotli_). The middleware will choose the best compression method supported by the client as indicated in the request's Accept-Encoding header. In order of preference:

  • Zstandard
  • Brotli
  • gzip

Summary of the project status:

.. _documentation: https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip .. _WhiteNoise: https://whitenoise.readthedocs.io/ .. _Can I use... Brotli: http://caniuse.com/#search=brotli

Installation and usage

The following requirements are supported and tested in all reasonable combinations:

  • Python versions: 2.7, 3.4, 3.5, 3.6, 3.7, 3.8.
  • Interpreters: CPython and PyPy.
  • Django versions: 1.11 (LTS), 2.0, 2.1, 2.2 (LTS), 3.0.

.. code:: shell

pip install --upgrade django-compression-middleware

To apply compression to all the views served by Django, add compression_middleware.middleware.CompressionMiddleware to the MIDDLEWARE setting:

.. code:: python

MIDDLEWARE = [
    # ...
    'compression_middleware.middleware.CompressionMiddleware',
    # ...
]

Remove GZipMiddleware and BrotliMiddleware if you used it before. Consult the Django documentation on the correct ordering of middleware_.

.. _ordering of middleware: https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip

Alternatively you can decorate views individually to serve them with compression:

.. code:: python

from compression_middleware.decorators import compress_page

@compress_page
def index_view(request):
    ...

Note that your browser might not send the br entry in the Accept-Encoding header when you test without HTTPS (common on localhost). You can force it to send the header, though. In Firefox, visit about:config and set network.http.accept-encoding to indicate support. Note that you might encounter some problems on the web with such a setting (which is why Brotli is only supported on secure connections by default).

Credits and Resources

The code and tests in this project are based on Django's GZipMiddleware and Vašek Dohnal's django-brotli. For compression, it uses the following modules to bind to fast C modules:

  • The zstandard_ bindings. It supports both a C module (for CPython) and CFFI which should be appropriate for PyPy. See the documentation for full details.
  • The Brotli_ bindings or brotlipy_. The latter is preferred on PyPy since it is implemented using cffi. But both should work on both Python implementations.
  • Python's builtin gzip_ module.

.. _zstandard: https://pypi.org/project/zstandard/ .. _Brotli: https://pypi.org/project/Brotli/ .. _brotlipy: https://pypi.org/project/brotlipy/ .. _gzip: https://docs.python.org/3/library/gzip.html

Further readding on Wikipedia:

  • HTTP compression <https://en.wikipedia.org/wiki/HTTP_compression>__
  • Zstandard <http://www.zstd.net/>__
  • Brotli <https://en.wikipedia.org/wiki/Brotli>__
  • gzip <https://en.wikipedia.org/wiki/Gzip>__

Contributing

  1. Clone this repository (git clone ...)
  2. Create a virtualenv
  3. Install package dependencies: pip install --upgrade -r requirements_dev.txt
  4. Change some code
  5. Run the tests: in the project root simply execute pytest, and afterwards preferably tox to test the full test matrix. Consider installing as many supported interpreters as possible (having them in your PATH is often sufficient).
  6. Submit a pull request and check for any errors reported by the Continuous Integration service.

License

The MPL 2.0 License

Copyright (c) 2019 Friedel Wolff <https://fwolff.net.za/>_.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].