Depending on your setup and preferences, there are multiple ways to run Emmett applications. In this chapter, we'll try to document the most common ones.
If you want to use an ASGI server not listed in this section, please refer to its documentation, remembering that your Emmett application object is the actual ASGI application (following spec version 3.0).
Changed in version 2.5
Emmett comes with Granian as its HTTP server. In order to run your application in production you can just use the included
emmett serve --host 0.0.0.0 --port 80
You can inspect all the available options of the
serve command using the
--help option. Here is the full list:
|Number of worker processes
|Number of threads
|Threading implementation (possible values: runtime,workers)
|Server interface (possible values: rsgi,asgi)
|HTTP protocol version (possible values: auto,1,2)
|Enable/disable websockets support
|Loop implementation (possible values: auto,asyncio,uvloop)
|Logging level (possible values: debug,info,warning,error,critical)
|Maximum connection queue
|Path to SSL certificate file
|Path to SSL key file
Changed in version 2.5
In case you want to stick with a more popular option, Emmett also comes with included support for Uvicorn.
You can just use the
emmett[uvicorn] extra during installation and rely on the
uvicorn command to serve your application.
The included server might suit most of the common demands, but whenever you need additional features, you can use Gunicorn.
Emmett includes a Gunicorn worker class allowing you to run ASGI applications with the Emmett's environment, while also giving you Gunicorn's fully-featured process management:
gunicorn myapp:app -w 4 -k emmett.asgi.workers.EmmettWorker
This allows you to increase or decrease the number of worker processes on the fly, restart worker processes gracefully, or perform server upgrades without downtime.
Even if Docker is not properly a deployment option, we think giving an example of a
Dockerfile for an Emmett application is proficient for deployment solutions using container orchestrators, such as Kubernetes or Mesos.
In order to keep the image lighter, we suggest to use the slim Python image as a source:
RUN mkdir -p /usr/src/deps
COPY requirements.txt /usr/src/deps
RUN pip install --no-cache-dir -r /usr/src/deps/requirements.txt
COPY ./ /app
CMD [ "emmett", "serve" ]