sanic_compress is an extension which allows you to easily gzip your Sanic responses. It is a port of the Flask-Compress extension.
Installation
Install with pip:
pip install sanic_compress
Usage
Usage is simple. Simply pass in the Sanic app object to the Compress class, and responses will be gzipped.
from sanic import Sanic
from sanic_compress import Compress
app = Sanic(__name__)
Compress(app)
Alternatively, if you want to initialize the Compress class later, you can do so with the init_app method;
compress = Compress()
app = Flask(__name__)
compress.init_app(app)
Options
Within the Sanic application config you can provide the following settings to control the behavior of sanic_compress. None of the settings are required.
COMPRESS_MIMETYPES: Set the list of mimetypes to compress here. - Default: ['text/html','text/css','text/xml','application/json','application/javascript']
COMPRESS_LEVEL: Specifies the gzip compression level (1-9). - Default: 6
COMPRESS_MIN_SIZE: Specifies the minimum size (in bytes) threshold for compressing responses. - Default: 500
A higher COMPRESS_LEVEL will result in a gzipped response that is smaller, but the compression will take longer.
Example of using custom configuration:
from sanic import Sanic
from sanic_compress import Compress
app = Sanic(__name__)
app.config['COMPRESS_MIMETYPES'] = set(['text/html', 'application/json'])
app.config['COMPRESS_LEVEL'] = 4
app.config['COMPRESS_MIN_SIZE'] = 300
Compress(app)
Note about gzipping static files:
Sanic is not at heart a file server. You should consider serving static files with nginx or on a separate file server.
Metadata
Release files for sanic_compress 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sanic_compress-0.1.1.tar.gz | 2.5 kB | Without provenance | Details for sanic_compress-0.1.1.tar.gz |
Release files / sanic_compress-0.1.1.tar.gz
| Download URL | sanic_compress-0.1.1.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
350123350caad62a6815f70b485fd98b6c3e94c1cdaefc4a192d3075d540522b
|
|
BLAKE2b-256 checksum How to use checksums |
4c76285235ef1755b75936bb16b5f9424b7ac60af8949f865fea63287b863cef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sanic_compress 0.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.