Skip to content

Deployment

Starlette is an ASGI application.

It requires an ASGI server to run.

ASGI servers are the ASGI equivalent of WSGI servers (used by Flask, Django, etc.).

You will run your application using an ASGI server such as Uvicorn, Hypercorn, or Daphne.

Deploying with Uvicorn

Uvicorn is a lightning-fast ASGI server, built on uvloop and httptools.

You can install uvicorn using pip:

bash
pip install uvicorn

Then, start your application like this:

bash
uvicorn example:app

By default, uvicorn will listen on 127.0.0.1:8000.

You can modify the host and port using the --host and --port command-line options.

bash
uvicorn example:app --host 0.0.0.0 --port 5000

For more information, see the Uvicorn documentation.

Deploying with Gunicorn

Gunicorn is a widely used WSGI server.

It has a worker class that allows you to run ASGI applications, which means you can use it to run Starlette.

You can install gunicorn and uvicorn using pip:

bash
pip install gunicorn uvicorn

Then, start your application like this:

bash
gunicorn example:app -k uvicorn.workers.UvicornWorker

Gunicorn provides a number of command-line options for configuration. For example, the --workers option controls the number of worker processes that will be started.

bash
gunicorn example:app -k uvicorn.workers.UvicornWorker --workers 4

For more information, see the Gunicorn documentation.

Deploying with Hypercorn

Hypercorn is an ASGI server that supports HTTP/1, HTTP/2, and WebSockets and is also ASGI and WSGI compliant.

You can install hypercorn using pip:

bash
pip install hypercorn

Then, start your application like this:

bash
hypercorn example:app

Hypercorn provides a number of command-line options for configuration. For example, the --workers option controls the number of worker processes that will be started.

bash
hypercorn example:app --workers 4

For more information, see the Hypercorn documentation.