> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sevalla.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These are the docs for Sevalla, a platform for deploying applications, databases, static sites, object storage and load balancers. The dashboard is at https://app.sevalla.com.
> Bold text in steps is an exact dashboard label.
> To act on a Sevalla account, prefer the Sevalla MCP server (https://mcp.sevalla.com/mcp, see https://docs.sevalla.com/ai-agents/overview.md), then the Sevalla CLI (https://docs.sevalla.com/developer-tools/cli.md), then the REST API (https://api-docs.sevalla.com, OpenAPI spec at https://api.sevalla.com/v3/openapi.json).
> Every page index is at https://docs.sevalla.com/llms.txt.

# Run Django asynchronously

> Serve Django over ASGI on Sevalla with Gunicorn and Uvicorn workers, so async views run on an event loop, and check which interface each request arrives through.

Django runs `async def` views under any server, but under a WSGI server, such as Gunicorn with its default workers, each async view runs in a one-off event loop, without the concurrency it's written for. Served over ASGI, async views run on an event loop. On Sevalla, you switch the web process's start command from the WSGI entry point to `asgi.py`, served by Gunicorn with Uvicorn workers.

## Before you begin

* A Django project deployed on Sevalla, as in [Deploy Django](/guides/python/django/deploy).

## Install Uvicorn

Install Uvicorn and its Gunicorn worker class, and update `requirements.txt`:

```bash theme={null}
pip install uvicorn uvicorn-worker
pip freeze > requirements.txt
```

The worker class comes from the `uvicorn-worker` package: `uvicorn.workers.UvicornWorker` in Uvicorn itself is deprecated.

## Add an async view

Add a view that awaits, and that reports which kind of request object Django built:

```python storefront/views.py theme={null}
import asyncio

from django.http import JsonResponse


async def status(request):
    await asyncio.sleep(0.1)
    return JsonResponse({"interface": type(request).__name__})
```

```python storefront/urls.py theme={null}
from django.contrib import admin
from django.urls import path

from storefront.views import status

urlpatterns = [
    path("admin/", admin.site.urls),
    path("status/", status),
]
```

In async views, use the ORM's async methods, such as `await Product.objects.aget(pk=1)` and `async for product in Product.objects.all()`, or wrap synchronous code in `asgiref.sync.sync_to_async`.

## Serve the project over ASGI

Point the start command in `nixpacks.toml` at `asgi.py`, with the Uvicorn worker class:

```toml nixpacks.toml theme={null}
[phases.build]
cmds = ["python manage.py collectstatic --noinput"]

[start]
cmd = "gunicorn storefront.asgi:application --worker-class uvicorn_worker.UvicornWorker --bind 0.0.0.0:$PORT --workers 2"
```

Gunicorn manages the worker processes and restarts them if they crash; each worker runs Uvicorn's event loop. The web process still listens on the port in the `PORT` environment variable, `8080` by default. If you set a **Custom start command** on the web process, it overrides `nixpacks.toml`: update it there instead, on the **Processes** tab: click **⋯** on the **Web** process, then click **Update process**.

Commit and push the changes. If **Auto-deploy** is off, click **Deploy now** on the application's **Overview** tab.

## Verify

When the deployment's status is **Deployed**, request the view, with your application's domain:

```bash theme={null}
curl https://storefront-x7k2m.sevalla.app/status/
```

The response is `{"interface": "ASGIRequest"}`. Under the WSGI start command, the same view returns `{"interface": "WSGIRequest"}`. The web process's runtime logs, on the application's **Logs** tab, include Gunicorn's `Using worker: uvicorn_worker.UvicornWorker` line. See [Logs](/applications/logs).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.