Flask is a microframework for Python, which is mostly used in web-backend development.There are projects in FOSSASIA that are using flask for development purposes such as Open Event Server, Query Server, Badgeyay. Optimization is indeed one of the most important steps for a successful software product. So, in this post some few off- the-hook tricks will be shown which will make your flask-app more fast and reliable.
Flask-Compress
- Flask-Compress is a python package which basically provides de-facto lossless compression to your Flask application.
- Enough with the theory, now let’s understand the coding part:
- First install the module
2. Then for a basic setup
3.That’s it! All it takes is just few lines of code to make your flask app optimized .To know more about the module check out flask-compress module.
Requirements Directory
- A common practice amongst different FOSSASIA projects which involves dividing requirements.txt files for development,testing as well as production.
- Basically when projects either use TRAVIS CI for testing or are deployed to Cloud Services like Heroku, there are some modules which are not really required at some places. For example: gunicorn is only required for deployment purposes and not for development.
- So how about we have a separate directory wherein different .txt files are created for different purposes.
- Below is the image of file directory structure followed for requirements in badgeyay project.
- As you can see different .txt files are created for different purposes
- dev.txt – for development
- prod.txt – for production(i.e. deployment)
- test.txt – for testing.
Resources
- Flask documentation: http://flask.pocoo.org/docs/
- Optimizing Flask App: https://damyanon.net/flask-series-optimizations/
- Badgeyay project: https://github.com/fossasia/badgeyay