Skip to main content

Flask running on asyncio.

Project description

aioflask

Build Status

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.
  • The cli.command() decorator accepts coroutines as well as regular

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.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

aioflask-0.1.0-py2.py3-none-any.whl (10.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: aioflask-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for aioflask-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1f0d6c456de327bea7294222dcc26398b7dae5fde4b95f9e2536151fa1c13eed
MD5 c86753ecdc862a762c6ec59c32b2c0fc
BLAKE2b-256 ece026ca7ba92118d60b51af02c1de48437a4f300cad914d8f958307dfc1cadd

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: aioflask-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for aioflask-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5a71d84a9e3509b0b3d34d9c78bb4a8248a43f002ea8c2701942009cce2ed967
MD5 a4f840a1409ca808f7b6f6cb4f61b48c
BLAKE2b-256 0c06ff3e3cbb2abaec821accb56cf95bebdfdef83c127d560bd33b28a155e21b

See more details on using hashes here.

Provenance

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