Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sunary/flask-optimize
Flask optimization: cache, minify html and gzip response
https://github.com/sunary/flask-optimize
flask gzip-response python
Last synced: 10 days ago
JSON representation
Flask optimization: cache, minify html and gzip response
- Host: GitHub
- URL: https://github.com/sunary/flask-optimize
- Owner: sunary
- License: other
- Created: 2016-04-28T13:55:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T20:15:52.000Z (over 1 year ago)
- Last Synced: 2024-09-19T11:42:56.121Z (about 2 months ago)
- Topics: flask, gzip-response, python
- Language: Python
- Size: 34.2 KB
- Stars: 53
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask-optimize
[![Build Status](https://travis-ci.org/sunary/flask-optimize.svg?branch=master)](https://travis-ci.org/sunary/flask-optimize)
**Flask optimization using cache, minify html and compress response**
https://pypi.python.org/pypi/flask-optimize
## Optimize parameters
### init_app:
**config:** Global config
Default:
```python
{
'html': {'htmlmin': True, 'compress': True, 'cache': 'GET-84600'},
'json': {'htmlmin': False, 'compress': True, 'cache': False},
'text': {'htmlmin': False, 'compress': True, 'cache': 'GET-600'}
}
````html`, `json`, `text`: keys for data type of response, see detail below
**config_update:** update into default global config
### optimize
**dtype:** Data type of response, will get value corresponding with key in global config.
- `html` *(default)*
- `text`
- `json`**htmlmin:** Override `htmlmin` in config by key **dtype**
```
None: using default value from global config
False: disable
True: enable minify html
```**compress:** Override `compress` in config by key **dtype**
```
None: using default value from global config
False: disable
True: enable compress content (using gzip)
```**cache:** Override `cache` in config by key **dtype**
```
None: using default value from global config
False: disable
integer value: enable all method, value is cached period (seconds)
GET-84600: enable for GET method only, cached period is 84600 seconds
```## Python code usage
```python
from flask import Flask
from flask_optimize import FlaskOptimizeflask_app = Flask(__name__)
flask_optimize = FlaskOptimize()@flask_app.route('/')
@flask_optimize.optimize()
def index():
return 'using Flask-optimize'@flask_app.route('/html')
@flask_optimize.optimize()
def html():
return '''
Default data type is html.
This content will be minified.
'''
@flask_app.route('/text')
@flask_optimize.optimize('text')
def text():
return '''
Data type response is text, so this content wasn't minified
'''
@flask_app.route('/json')
@flask_optimize.optimize('json')
def json():
return {'text': 'anything', 'other_values': [1, 2, 3, 4]}if __name__ == '__main__':
flask_app.run('localhost', 8080, debug=True)
```## Install
```shell
pip install flask-optimize
```## Requirements: ##
* Python 2.x
* Python 3.x