Skip to main content

aioflask

Build status codecov

Flask 2.x running on asyncio!

Is there a purpose for this, now that Flask 2.0 is out with support for async views? Yes! Flask's own support for async handlers is very limited, as the application still runs inside a WSGI web server, which severely limits scalability. With aioflask you get a true ASGI application, running in a 100% async environment.

WARNING: This is an experiment at this point. Not at all production ready!

Quick start

To use async view functions and other handlers, use the aioflask package instead of flask.

The aioflask.Flask class is a subclass of flask.Flask that changes a few minor things to help the application run properly under the asyncio loop. In particular, it overrides the following aspects of the application instance:

  • The route, before_request, before_first_request, after_request, teardown_request, teardown_appcontext, errorhandler and cli.command decorators accept coroutines as well as regular functions. The handlers all run inside an asyncio loop, so when using regular functions, care must be taken to not block.
  • The WSGI callable entry point is replaced with an ASGI equivalent.
  • The run() method uses uvicorn as web server.

There are also changes outside of the Flask class:

  • The flask aiorun command starts an ASGI application using the uvicorn web server.
  • The render_template() and render_template_string() functions are asynchronous and must be awaited.
  • The context managers for the Flask application and request contexts are async.
  • The test client and test CLI runner use coroutines.

Example

import asyncio
from aioflask import Flask, render_template

app = Flask(__name__)

@app.route('/')
async def index():
    await asyncio.sleep(1)
    return await render_template('index.html')

Metadata

Release files for aioflask 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aioflask 0.4.0
File Size Uploaded
aioflask-0.4.0.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aioflask 0.4.0
File Interpreter ABI Platform
aioflask-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.2 kB

Release files / aioflask-0.4.0.tar.gz

Download URL aioflask-0.4.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
96403709fff88351c606667fce1a5a66bdef2d634a04b358713c8304216db68f
BLAKE2b-256 checksum
How to use checksums
9d07ac0afe199fde1764927ce68f254e9fe3c174c4bb689f74b8a40974c5b4cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.3

Release files / aioflask-0.4.0-py3-none-any.whl

Download URL aioflask-0.4.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f0c2327f973a853a37b1506039e74bc532d58a009427e66bc37bf1e7bffbff2
BLAKE2b-256 checksum
How to use checksums
b6fc961dc7419b4095eedb87116dc7b4c4542cd5fa14403dc8b85ef3956d9383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page