quart-flask-patch (0.3.1)
Installation
pip install --index-url https://git.yiprawr.dev/api/packages/daniel156161/pypi/simple/ --extra-index-url https://pypi.org/simple quart-flask-patchAbout this package
Quart-Flask-Patch is a Quart extension that patches Quart to work with Flask extensions.
Quart-Flask-Patch
|Build Status| |pypi| |python| |license|
Quart-Flask-Patch is a Quart extension that patches Quart to work with Flask extensions.
Quickstart
Quart-Flask-Patch must be imported first in your main module, so that the patching occurs before any other code is initialised. For example, if you want to use Flask-Login,
.. code-block:: python
import quart_flask_patch
from quart import Quart import flask_login
app = Quart(name) login_manager = flask_login.LoginManager() login_manager.init_app(app)
Extensions known to work
The following flask extensions are tested and known to work with quart,
Flask-BCrypt <https://flask-bcrypt.readthedocs.io>_Flask-Caching <https://flask-caching.readthedocs.io>_Flask-KVSession <https://github.com/mbr/flask-kvsession>_Flask-Limiter <https://github.com/alisaifee/flask-limiter/>_ See alsoQuart-Rate-Limiter <https://github.com/pgjones/quart-rate-limiter>_Flask-Login <https://github.com/maxcountryman/flask-login/>_ See alsoQuart-Login <https://github.com/0000matteo0000/quart-login>_ orQuart-Auth <https://github.com/pgjones/quart-auth>_Flask-Mail <https://pythonhosted.org/Flask-Mail/>_Flask-Mako <https://pythonhosted.org/Flask-Mako/>_Flask-Seasurf <https://github.com/maxcountryman/flask-seasurf/>_Flask-SQLAlchemy <https://flask-sqlalchemy.palletsprojects.com>_ See alsoQuart-DB <https://github.com/pgjones/quart-db>_Flask-WTF <https://flask-wtf.readthedocs.io>_
Extensions known not to work
The following flask extensions have been tested are known not to work with quart,
Flask-CORS <https://github.com/corydolphin/flask-cors>, as it usesapp.make_responsewhich must be awaited. TryQuart-CORS <https://github.com/pgjones/quart-cors>instead.Flask-Restful <https://flask-restful.readthedocs.io>_ as it subclasses the Quart (app) class with synchronous methods overriding asynchronous methods. TryQuart-OpenApi <https://github.com/factset/quart-openapi/>_ orQuart-Schema <https://github.com/pgjones/quart-schema>_ instead.
Caveats
Flask extensions must use the global request proxy variable to access
the request, any other access e.g. via
~quart.local.LocalProxy._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.
Contributing
Quart-Flask-Patch is developed on GitHub <https://github.com/pgjones/quart-flask-patch>. If you come across
an issue, or have a feature request please open an issue <https://github.com/pgjones/quart-flask-patch/issues>. If you want
to contribute a fix or the feature-implementation please do (typo
fixes welcome), by proposing a merge request <https://github.com/pgjones/quart-flask-patch/merge_requests>_.
Testing
The best way to test Quart-Flask-Patch is with `uv
<https://docs.astral.sh/uv/>`_,
.. code-block:: console
$ uv run --group test pytest --cov=quart_flask_patch
$ uv run --group format black --check --diff src/quart_flask_patch/ tests/
$ uv run --group format isort --check --diff src/quart_flask_patch/ tests
$ uv run --group pep8 flake8 src/quart_flask_patch/ tests/
$ uv run --group typing mypy src/quart_flask_patch/
this will run the tests and check the code style.
Help
----
The Quart-Flask-Patch `documentation
<https://quart-flask-patch.readthedocs.io/en/latest/>`_ is the best
places to start, after that try searching `stack overflow
<https://stackoverflow.com/questions/tagged/quart>`_ or ask for help
`on gitter <https://gitter.im/python-quart/lobby>`_. If you still
can't find an answer please `open an issue
<https://github.com/pgjones/quart-flask-patch/issues>`_.
.. |Build Status| image:: https://github.com/pgjones/quart-flask-patch/actions/workflows/ci.yml/badge.svg
:target: https://github.com/pgjones/quart-flask-patch/commits/main
.. |pypi| image:: https://img.shields.io/pypi/v/quart-flask-patch.svg
:target: https://pypi.python.org/pypi/Quart-Flask-Patch/
.. |python| image:: https://img.shields.io/pypi/pyversions/quart-flask-patch.svg
:target: https://pypi.python.org/pypi/Quart-Flask-Patch/
.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://github.com/pgjones/quart-flask-patch/blob/main/LICENSE