aioflask
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,errorhandlerandcli.commanddecorators 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 aioruncommand starts an ASGI application using the uvicorn web server. - The
render_template()andrender_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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aioflask-0.4.0.tar.gz | 12.6 kB | Without provenance | Details for aioflask-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aioflask-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for aioflask-0.4.0-py3-none-any.whl |
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
|
Security for aioflask 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.