Skip to main content

Flask running on asyncio.

Project description

aioflask

Build status codecov

Flask running on asyncio!

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 run command starts the uvicorn web server.
  • The render_template() function is asynchronous and must be awaited. The sync render version is available as render_template_sync().

Example

import asyncio
from aioflask import Flask

app = Flask(__name__)

@app.route('/')
async def index():
    await asyncio.sleep(1)
    return "Look Ma, I'm async!"

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

aioflask-0.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

aioflask-0.2.0-py2.py3-none-any.whl (10.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aioflask-0.2.0.tar.gz.

File metadata

  • Download URL: aioflask-0.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for aioflask-0.2.0.tar.gz
Algorithm Hash digest
SHA256 274695c3f81e84b2ef1c99bd9c66a111d50acaeb3c17339a39c596e2e4921024
MD5 b078a0eaa4b65d81611a40d07bb18fb1
BLAKE2b-256 ca170323d7caa3b31c141e6668df607bd45a14262ba317e94b0b550206d9ed54

See more details on using hashes here.

File details

Details for the file aioflask-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: aioflask-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for aioflask-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 19e87283f7317f75f032c65714ff2ecc9d2fd69295f3d1407469d2b3bf38b142
MD5 bdab24321c2c512b7db66197718f2fb3
BLAKE2b-256 560bebe43e38a7993a5f52c2f4c9860fc2563ea7aa018b6e2a3c45cb8846f735

See more details on using hashes here.

Supported by

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