- gunicorn configuration for FastAPI / BookServer

This file configures gunicorn to use Uvicorn to run FastAPI which runs the BookServer.

See also the gunicorn config docs.


These are listed in the order prescribed by `PEP 8`_.

Standard library

import multiprocessing
import os

Third-party imports


Local application imports

from common_config import *  # noqa: F401, F403


chdir: Change directory to specified directory before loading apps. Otherwise gunicorn does not know where to look for changes to your code.

if os.environ["BOOK_SERVER_CONFIG"] == "development":
    chdir = os.environ["BOOK_SERVER_PATH"]

wsgi_app: A WSGI application path in pattern $(MODULE_NAME):$(VARIABLE_NAME).

wsgi_app = "bookserver.main:app"

workers: The number of worker processes for handling requests. Pick this based on CPU count.

workers = multiprocessing.cpu_count() * 2 + 1

worker_class: The type of workers to use. Use uvicorn’s worker class for gunicorn.

worker_class = "uvicorn.workers.UvicornWorker"

Detach and run in the background

daemon = True
capture_output = True
enable_stdio_inheritance = True
pidfile = "/srv/"

reload_engine = “inotify”