Flask 2.0 pours out updates to web application framework

Flask 2.0 pours out updates to web application framework

The Flask lightweight web application framework has hit release 2.0, delivering a wealth of updates such as async views, while deprecating support for older versions of Python.

Along with other tools developed by The Pallets Projects team, Flask 2.0 has dropped support for Python 2 and 3.5, requiring Python 3.6 as the minimum supported version. The team said it plans to follow CPython’s supported versions in future.

Among the highlights of this release is support of async views and other callbacks such as error handlers, defined with async def. Regular sync views continue to work unchanged, but Asynchronous Server Gateway Interface (ASGI) features such as web sockets are not supported. The project team said it aims to add further support for async.

Flask 2.0 implements better CLI errors for the situation where an app could not be loaded. Running the development server now shows errors immediately, and they are only deferred on reloads.

Another change in Flask 2.0 is that browsers will now cache based on content rather than a 12-hour timer. This means changes to static content such as CSS styles will be reflected immediately on reload without needing to clear the cache.

Meanwhile, a new Config.from_file function allows Flask to load configuration data from any file format, while the flask shell command enables tab completion in a similar manner to how the regular python shell does.

Flask 2.0 now enables blueprints to be nested under other blueprints, which will allow for a more layered approach to organising an application.

Also added are route decorators for common HTTP API methods. According to the project team, this means that @app.post(“/login”) becomes a shortcut for @app.route(“/login”, methods=[“POST”]).

A full list of the changes in Flask 2.0 is available in the changelog, while Flask 2.0 can be installed from the Python Package Index (PyPI) using the pip package installer.