A fork of Quart that uses AnyIO
Project description
AnyQuart
Quart runs on Asyncio and when you want to run it on Trio event loop you use quart-trio extension.
AnyQuart is Quart running on AnyIO. It is a fork of Quart 0.20.1.
All credit for Quart goes to the Pallets team.
Usage
You will have to replace quart with anyquart and Quart with AnyQuart.
Install from PyPI using an installer such as pip. Requires Python 3.10+.
$ pip install anyquart
Save the following as app.py.
from anyquart import AnyQuart, websocket, render_template
app = AnyQuart(__name__)
@app.route("/")
async def hello():
return await render_template("index.html")
@app.route("/api")
async def json():
return {"hello": "world"}
@app.websocket("/ws")
async def ws():
while True:
await websocket.send("hello")
await websocket.send_json({"hello": "world"})
$ anyquart run
* Running on http://127.0.0.1:5000 (CTRL + C to quit)
Testing
Pytest does not natively support async test functions hence we need an async framework for async tests and fixtures.
Quart uses pytest-asyncio, here we use AnyIO's pytest plugin. You will need to specify which backend your tests run on via the anyio_backend fixture and decorate your asynchronous tests with @pytest.mark.anyio.
import pytest
from app import app
@pytest.fixture()
def anyio_backend():
return "trio" # you can replace with "asyncio"
@pytest.fixture()
def test_client():
return app.test_client()
@pytest.mark.anyio
async def test_do_something(test_client) -> None:
response = await test_client.get("/")
assert response.status_code == 200
assert await response.json == {"hello": "world"}
Differences from Quart
- Uses Anycorn instead of Hypercorn as the development server
- Works with both asyncio and Trio via AnyIO
- Uses AnyIO's file I/O instead of aiofiles
- AnyIO primitives work freely in route handlers, giving you structured concurrency out of the box
- Tests need
@pytest.mark.anyioand theanyio_backendfixture instead of pytest-asyncio
Refer to the Quart documentation for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anyquart-0.1.0.tar.gz.
File metadata
- Download URL: anyquart-0.1.0.tar.gz
- Upload date:
- Size: 64.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a1ab1dd51d2ce133e3b20372c1d88d960a3e938c948f2d7547146ab729245a6
|
|
| MD5 |
1fa7e82df05a70ac95d55e26414cca3c
|
|
| BLAKE2b-256 |
916fbe8edef101cf2d68043538fd976da751333a81fe694902d369ea817d86b4
|
Provenance
The following attestation bundles were made for anyquart-0.1.0.tar.gz:
Publisher:
publish.yaml on EmmanuelNiyonshuti/anyquart
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anyquart-0.1.0.tar.gz -
Subject digest:
8a1ab1dd51d2ce133e3b20372c1d88d960a3e938c948f2d7547146ab729245a6 - Sigstore transparency entry: 1938250388
- Sigstore integration time:
-
Permalink:
EmmanuelNiyonshuti/anyquart@fe2a37a84845d0b34c1cb9263a0a24677a1995c2 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/EmmanuelNiyonshuti
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@fe2a37a84845d0b34c1cb9263a0a24677a1995c2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file anyquart-0.1.0-py3-none-any.whl.
File metadata
- Download URL: anyquart-0.1.0-py3-none-any.whl
- Upload date:
- Size: 78.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33adf29f0a45a26a23d265312c1cb3f16e5075b3f7bb5703ce7443b700539999
|
|
| MD5 |
075129c8b1fb9b35a7c6e1c131469943
|
|
| BLAKE2b-256 |
588fb69eaea36f06bc25de8f054b6d831a7dc8921f331969e16f0b4c4bd749d0
|
Provenance
The following attestation bundles were made for anyquart-0.1.0-py3-none-any.whl:
Publisher:
publish.yaml on EmmanuelNiyonshuti/anyquart
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anyquart-0.1.0-py3-none-any.whl -
Subject digest:
33adf29f0a45a26a23d265312c1cb3f16e5075b3f7bb5703ce7443b700539999 - Sigstore transparency entry: 1938250457
- Sigstore integration time:
-
Permalink:
EmmanuelNiyonshuti/anyquart@fe2a37a84845d0b34c1cb9263a0a24677a1995c2 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/EmmanuelNiyonshuti
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@fe2a37a84845d0b34c1cb9263a0a24677a1995c2 -
Trigger Event:
push
-
Statement type: