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.

Source Distribution

sanic_brogz-0.1.3.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sanic_brogz-0.1.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file sanic_brogz-0.1.3.tar.gz.

File metadata

  • Download URL: sanic_brogz-0.1.3.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.0 CPython/3.7.0

File hashes

Hashes for sanic_brogz-0.1.3.tar.gz
Algorithm Hash digest
SHA256 74b40833eaad6f65c20a27e6d252bc477dc533f3774c99ba1cabf306b75e39d7
MD5 8c973b985f1e38111ff0b8ef624b4eac
BLAKE2b-256 05f0c7ea802b04616423f0e2c52881a68071947fa3858cb32c595e812bc4ecf9

See more details on using hashes here.

File details

Details for the file sanic_brogz-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sanic_brogz-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.0 CPython/3.7.0

File hashes

Hashes for sanic_brogz-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7b1f39911df234ebdd4609f0175667610abbbef65ab949d997ecee0f77c04563
MD5 7a145b534c9391bb2b96d65e0cedbccc
BLAKE2b-256 5812fc246d1058cae149b6d4063edb7b46501d5af2d87a749e3c3eae772a2f29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page