β‘ Asynchronous Server Gateway (ASGI)ΒΆ
Duck comes with built-in asynchronous support right out of the box.
From custom sockets (xsockets) to full async handling, everything is designed for speed, scalability, and modern protocols π
π§ Enabling Async HandlingΒΆ
Simply add the following setting in your settings.py:
ASYNC_HANDLING = True
This single flag turns on asynchronous request handling in your app.
π NotesΒΆ
β The default ASGI handles everything automatically β no need to modify unless you want custom behavior.
π Async environment supports protocols like WebSockets and HTTP/2 natively.
π While itβs recommended to define your views as async, non-async views will still work (theyβre automatically converted).
βοΈ Want a different event loop? Set
ASYNC_LOOP(e.g.uvloop) in your settings.
π¨βπ» Defining Async ViewsΒΆ
You can define async views in two main ways:
1οΈβ£ Async Views as FunctionsΒΆ
# views.py
async def myview(request):
# Some async code to return HttpResponse
...
2οΈβ£ Async Views as ClassesΒΆ
# views.py
from duck.views import View
class MyView(View):
def strictly_async(self):
# Return True to force this view to always use async
# (disables automatic sync β async conversion).
...
async def run(self):
# Some async code to return HttpResponse
...
β¨ With Duckβs ASGI, you get true async support, seamless integration with modern protocols, and the flexibility to use function-based or class-based async views.
Start writing async today and unlock maximum performance! π