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:
pip install uvicorn
Then, start your application like this:
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.
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:
pip install gunicorn uvicorn
Then, start your application like this:
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.
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:
pip install hypercorn
Then, start your application like this:
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.
hypercorn example:app --workers 4
For more information, see the Hypercorn documentation.