Skip to main content

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.

Differences from Quart

AnyQuart and Quart are essentially the same thing. The only difference is the name and the internals(Asyncio replaced with AnyIO). This also means the testing setup changes, which is explained in the Testing section below.

  • Works with both asyncio and Trio code via AnyIO, giving you structured concurrency out of the box.
  • Uses Anycorn instead of Hypercorn as the development server.
  • aiofiles dropped, AnyIO's file I/O is used instead.
  • pytest-asyncio replaced by AnyIO pytest plugin.
  • Runs on Python 3.10+ .

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 requires a plugin to run asynchronous test functions and fixtures. Quart uses pytest-asyncio, while AnyQuart uses 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"}

Refer to the Quart documentation for more details.

Contributing

Issues and Pull Requests are welcome.

Contributors ✨

See All Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anyquart-0.1.1.tar.gz (64.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anyquart-0.1.1-py3-none-any.whl (78.2 kB view details)

Uploaded Python 3

File details

Details for the file anyquart-0.1.1.tar.gz.

File metadata

  • Download URL: anyquart-0.1.1.tar.gz
  • Upload date:
  • Size: 64.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for anyquart-0.1.1.tar.gz
Algorithm Hash digest
SHA256 326f7c34ae82fa94c6deff0e4f5d889261aa39a540f8f880d4fc35720c74642b
MD5 29695c7e6a0b8579ffc0a7dec9743c78
BLAKE2b-256 e333015d8eda357da8f4f178d7a59de605abeff5abfa2826477846b3423531bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyquart-0.1.1.tar.gz:

Publisher: publish.yaml on EmmanuelNiyonshuti/anyquart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anyquart-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: anyquart-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 78.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for anyquart-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2268dbfe85a465a2c41d981b24ad081a9db44599f69dfc9b4b942e048e3725d
MD5 410accbfd417abe8f193619bebf8fc2b
BLAKE2b-256 6801a3ad88af02bc5bb0d5b641447dd260cdf3b5cd5db3248a16b117cc7c09e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyquart-0.1.1-py3-none-any.whl:

Publisher: publish.yaml on EmmanuelNiyonshuti/anyquart

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page