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.

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.anyio and the anyio_backend fixture instead of pytest-asyncio

Refer to the Quart documentation for more details.

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.0.tar.gz (64.8 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.0-py3-none-any.whl (78.8 kB view details)

Uploaded Python 3

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

Hashes for anyquart-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a1ab1dd51d2ce133e3b20372c1d88d960a3e938c948f2d7547146ab729245a6
MD5 1fa7e82df05a70ac95d55e26414cca3c
BLAKE2b-256 916fbe8edef101cf2d68043538fd976da751333a81fe694902d369ea817d86b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyquart-0.1.0.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.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

Hashes for anyquart-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33adf29f0a45a26a23d265312c1cb3f16e5075b3f7bb5703ce7443b700539999
MD5 075129c8b1fb9b35a7c6e1c131469943
BLAKE2b-256 588fb69eaea36f06bc25de8f054b6d831a7dc8921f331969e16f0b4c4bd749d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyquart-0.1.0-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