Skip to main content

Quart-Compress

Version Build Status Coverage Status License

Quart-Compress allows you to easily compress your Quart application's responses with gzip.

The preferred solution is to have a server (like Nginx) automatically compress the static files for you. If you don't have that option Quart-Compress will solve the problem for you.

How it works

Quart-Compress both adds the various headers required for a compressed response and gzips the response data. This makes serving gzip compressed static files extremely easy.

Internally, every time a request is made the extension will check if it matches one of the compressible MIME types and will automatically attach the appropriate headers.

Installation

If you use pip then installation is simply:

$ pip install quart-compress

or, if you want the latest github version:

$ pip install git+git://github.com/AceFire6/quart-compress.git

Using Quart-Compress

Quart-Compress is incredibly simple to use. In order to start gzip'ing your Quart application's assets, the first thing to do is let Quart-Compress know about your quart.Quart application object.

from quart import Quart
from quart_compress import Compress

app = Quart(__name__)
Compress(app)

In many cases, however, one cannot expect a Quart instance to be ready at import time, and a common pattern is to return a Quart instance from within a function only after other configuration details have been taken care of. In these cases, Quart-Compress provides a simple function, quart_compress.Compress.init_app, which takes your application as an argument.

from quart import Quart
from quart_compress import Compress

compress = Compress()

def start_app():
    app = Quart(__name__)
    compress.init_app(app)
    return app

In terms of automatically compressing your assets using gzip, passing your quart.Quart object to the quart_compress.Compress object is all that needs to be done.

Options

Within your Quart application's settings you can provide the following settings to control the behavior of Quart-Compress. None of the settings are required.

Option Description Default
COMPRESS_MIMETYPES Set the list of mimetypes to compress here. [
'text/html',
'text/css',
'text/xml',
'application/json',
'application/javascript'
]
COMPRESS_LEVEL Specifies the gzip compression level. 6
COMPRESS_MIN_SIZE Specifies the minimum file size threshold for compressing files. 500
COMPRESS_CACHE_KEY Specifies the cache key method for lookup/storage of response data. None
COMPRESS_CACHE_BACKEND Specified the backend for storing the cached response data. None
COMPRESS_REGISTER Specifies if compression should be automatically registered. True

Metadata

Release files for quart-compress 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quart-compress 0.2.1
File Size Uploaded
quart-compress-0.2.1.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quart-compress 0.2.1
File Interpreter ABI Platform
quart_compress-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.2 kB

Release files / quart-compress-0.2.1.tar.gz

Download URL quart-compress-0.2.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
63af5e6370aa7850fb219d22e1db89965aeb13b8f27bc83e7f9a44118faa3c54
BLAKE2b-256 checksum
How to use checksums
02fcc891471c10f9a7789c0b4a1cdb7c6cf10abfc801772ed0bdf4b19df0afbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.2

Release files / quart_compress-0.2.1-py3-none-any.whl

Download URL quart_compress-0.2.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41cd0cc8d26905a45025ddda7022461a71b9d1d950b21b006dc106a1c41c75ef
BLAKE2b-256 checksum
How to use checksums
8293fc1bfc411a89baf3d1124e625fdacd09be88fdc67adec260bcff408803b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

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