Flask 2.0 Major Release Updates
Finally, with the release of Flask 2.0, and hearing the podcast of the flask team, it is official that Flask is the most popular python web framework to date. Here are the stats discussed in the podcast.
Since 11 years of its inception, Flask has proven itself a powerful microservices and application development framework for python developers and organizations. And yes, Flask 2.0.0 has been released on the 5th of May 2021 giving all the python developers out there something to think about.
As a python enthusiast myself, I would like to list out the major updates that are released with this version of Flask. Without further ado, below is a list of major updates:
??? Support for Python3.6+ is added.
?? No support for python version 2.7 and 3.5. Probably because even Python3.5 has reached its end of life with the last release version 3.5.10.
?? More readable and short route decorators added for common HTTP methods.
For example:
@app.route("/auth", methods=["POST"])
Can also now be written as:
@app.post("/auth")
?? Initial async-await support (optional install flask[async]), that allows for async route handlers, error handlers, before/after request, and teardown functions. Here is an example from the docs:
@app.route("/get-data") async def get_data(): data = await async_db_query(...)
return jsonify(data)
?? Now for microservice developers - Nested blueprints are supported. Now, you can use register_blueprint(another_app) to nest blueprints. Here is an example from docs:
def create_app(): app = ... # existing code omitted from . import auth app.register_blueprint(auth.bp)
return app
?? If you work with files - Flask has done one update in the send_file() utility, that it will now raise ValueError if an IO object is passed in text mode. Previously, it used to return an empty file with a 200 status code.
?? This release of Flask brings lots of deprecations. So don't be alarmed when you see a lot of deprecation warnings when you run the Flask 2.0 server (BTW I have seen the list -- you can panic ?? ). You can find a detailed list of deprecations on the Flask website.
Well, that is all I can list out for you folks. There are many other updates related to improved type hinting, default encoding, etc.
I know, a few of you are thinking about using Flask2.0 as your next python framework, I would just say one thing:
Lets be optimistic and have an open mind for FastAPI ??
Follow me for more interesting articles on Python and AWS. You can read more of my blogs and findings on Medium - Varun Singh.