Skip to main content

An extension which allows you to easily brotli compress or gzip your Sanic responses.

Project description

sanic_brogz is an extension which allows you to easily brotli compress or gzip your Sanic responses. It is a fork of the sanic_compress package which is a port of the Flask-Compress extension.

Installation

Install with pip:

pip install sanic_brogz

Usage

Usage is simple. Simply pass in the Sanic app object to the Compress class, and responses will be brotli compressed or gzipped.

from sanic import Sanic
from sanic_brogz import Compress

app = Sanic(__name__)
Compress(app)

Options

Within the Sanic application config you can provide the following settings to control the behavior of sanic_brogz. 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) or brotli compression level (1-11). - 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_brogz import Compress

app = Sanic(__name__)
app.config['COMPRESS_MIMETYPES'] = {'text/html', 'application/json'}
app.config['COMPRESS_LEVEL'] = 4
app.config['COMPRESS_MIN_SIZE'] = 300
Compress(app)

Note about compressing static files:

Sanic is not at heart a file server. You should consider serving static files with nginx or on a separate file server.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sanic-brogz, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size sanic_brogz-0.1.3-py3-none-any.whl (3.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size sanic_brogz-0.1.3.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page