https://github.com/pgjones/quart-flask-patch
Quart extension that patches Quart to work with Flask extensions.
https://github.com/pgjones/quart-flask-patch
quart
Last synced: 10 months ago
JSON representation
Quart extension that patches Quart to work with Flask extensions.
- Host: GitHub
- URL: https://github.com/pgjones/quart-flask-patch
- Owner: pgjones
- License: mit
- Created: 2023-05-11T18:36:52.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-14T13:00:02.000Z (almost 2 years ago)
- Last Synced: 2025-03-23T12:41:29.821Z (11 months ago)
- Topics: quart
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 16
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
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 `_
- `Flask-Caching `_
- `Flask-KVSession `_
- `Flask-Limiter `_ See
also `Quart-Rate-Limiter
`_
- `Flask-Login `_ See
also `Quart-Login `_
or `Quart-Auth `_
- `Flask-Mail `_
- `Flask-Mako `_
- `Flask-Seasurf `_
- `Flask-SQLAlchemy `_
See also `Quart-DB `_
- `Flask-WTF `_
Extensions known not to work
----------------------------
The following flask extensions have been tested are known not to work
with quart,
- `Flask-CORS `_, as it
uses ``app.make_response`` which 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
`_ or `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
`_. If you come across
an issue, or have a feature request please open an `issue
`_. If you want
to contribute a fix or the feature-implementation please do (typo
fixes welcome), by proposing a `merge request
`_.
Testing
~~~~~~~
The best way to test Quart-Flask-Patch is with `Tox
`_,
.. code-block:: console
$ pip install tox
$ tox
this will check the code style and run the tests.
Help
----
The Quart-Flask-Patch `documentation
`_ is the best
places to start, after that try searching `stack overflow
`_ or ask for help
`on gitter `_. If you still
can't find an answer please `open an issue
`_.
.. |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