Using Flask Extensions#
Flask extensions can be used with Quart, with some caveats. To do so
the very first import in your code must be
as this will add modules purporting to be Flask modules for later use
by the extension. For example,
import quart.flask_patch from quart import Quart import flask_login app = Quart(__name__) login_manager = flask_login.LoginManager() login_manager.init_app(app) ...
Flask extensions must use the global request proxy variable to access
the request, any other access e.g. via
_get_current_object() will require
asynchronous access. To enable this the request body must be fully
received before any part of the request is handled, which is a
limitation not present in vanilla flask.
Trying to use Flask alongside Quart in the same runtime will likely not work, and lead to surprising errors.
The flask extension must be limited to creating routes, using the request and rendering templates. Any other more advanced functionality may not work.
Synchronous functions will not run in a separate thread (unlike Quart normally) and hence may block the event loop.
Finally the flask_patching system also relies on patching asyncio, and hence other implementations or event loop policies are unlikely to work.
A list of officially supported flask extensions exist here of those a few have been tested against Quart (the extensions tested are still supported and don’t require external services). The following flask extensions are tested and known to work with quart,
The following flask extensions have been tested are known not to work with quart,
Flask-CORS, as it uses
app.make_responsewhich must be awaited. Try Quart-CORS instead.
Flask-Restful as it subclasses the Quart (app) class with synchronous methods overriding asynchronous methods. Try Quart-OpenApi instead.