All Projects → miguelgrinberg → aioflask

miguelgrinberg / aioflask

Licence: MIT license
Flask running on asyncio!

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to aioflask

Web Applications With Fastapi Course
Demo code and other handouts for students of our FastAPI Web Apps course.
Stars: ✭ 56 (-70.83%)
Mutual labels:  asyncio, async-await
Cppcoro
A library of C++ coroutine abstractions for the coroutines TS
Stars: ✭ 2,118 (+1003.13%)
Mutual labels:  asyncio, async-await
Greenletio
Asyncio integration with sync code using greenlets.
Stars: ✭ 102 (-46.87%)
Mutual labels:  asyncio, async-await
Async Reduce
Reducer for similar simultaneously coroutines
Stars: ✭ 17 (-91.15%)
Mutual labels:  asyncio, async-await
Aiohttp admin
admin interface for aiohttp application http://aiohttp-admin.readthedocs.io
Stars: ✭ 207 (+7.81%)
Mutual labels:  asyncio, async-await
Asyncio
asyncio historical repository
Stars: ✭ 952 (+395.83%)
Mutual labels:  asyncio, async-await
Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (-41.67%)
Mutual labels:  asyncio, async-await
kbio
Another Async IO Framework based on io_uring
Stars: ✭ 54 (-71.87%)
Mutual labels:  asyncio, async-await
Aioodbc
aioodbc - is a library for accessing a ODBC databases from the asyncio
Stars: ✭ 206 (+7.29%)
Mutual labels:  asyncio, async-await
Aiomisc
aiomisc - miscellaneous utils for asyncio
Stars: ✭ 200 (+4.17%)
Mutual labels:  asyncio, async-await
Aiomonitor
aiomonitor is module that adds monitor and python REPL capabilities for asyncio application
Stars: ✭ 430 (+123.96%)
Mutual labels:  asyncio, async-await
Pulsar
Event driven concurrent framework for Python
Stars: ✭ 1,867 (+872.4%)
Mutual labels:  greenlet, asyncio
Anyio
High level compatibility layer for multiple asynchronous event loop implementations on Python
Stars: ✭ 343 (+78.65%)
Mutual labels:  asyncio, async-await
Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+4194.79%)
Mutual labels:  asyncio, async-await
Sqlalchemy aio
Asyncio strategy for SQLAlchemy.
Stars: ✭ 299 (+55.73%)
Mutual labels:  asyncio, async-await
Riprova
Versatile async-friendly library to retry failed operations with configurable backoff strategies
Stars: ✭ 106 (-44.79%)
Mutual labels:  asyncio, async-await
nardis
A small web framework based on ASGI
Stars: ✭ 14 (-92.71%)
Mutual labels:  asyncio, async-await
Aiozipkin
Distributed tracing instrumentation for asyncio with zipkin
Stars: ✭ 161 (-16.15%)
Mutual labels:  asyncio, async-await
Gevent
Coroutine-based concurrency library for Python
Stars: ✭ 5,656 (+2845.83%)
Mutual labels:  greenlet, asyncio
tomodachi
💻 Microservice library / framework using Python's asyncio event loop with full support for HTTP + WebSockets, AWS SNS+SQS, RabbitMQ / AMQP, middleware, etc. Extendable for GraphQL, protobuf, gRPC, among other technologies.
Stars: ✭ 170 (-11.46%)
Mutual labels:  asyncio, async-await

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')
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].