# sanic_brogz
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](https://github.com/subyraman/sanic_compress) package which is a port of the [Flask-Compress](https://github.com/libwilliam/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.
```python
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:
```python
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.
PyPI 官网下载 | sanic_brogz-0.1.2.tar.gz
版权申诉
113 浏览量
2022-01-29
20:13:35
上传
评论
收藏 3KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- 课设毕设基于SSM的个人交友网站 LW+PPT+源码可运行.zip
- 课设毕设基于SSM的高校信息资源共享平台 LW+PPT+源码可运行.zip
- 课设毕设基于SSM的高校二手交易平台 LW+PPT+源码可运行.zip
- Z`@9ZFCVIJ41EJ2%J$RWI3S.png
- 课设毕设基于SSM的艺诚美业管理系统 LW+PPT+源码可运行.zip
- 基于STM8j003单片机设计MICRO-USB接口 圆环形PCB小板AD设计硬件(原理图+PCB+封装库)文件.zip
- Excel模板个人简历稳重大气单页22.docx
- Excel模板个人简历稳重大气单页24.docx
- Excel模板个人简历稳重大气单页25.docx
- Excel模板个人简历稳重大气单页07.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈