uvicorn.txt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ==============================
  2. How to use Django with Uvicorn
  3. ==============================
  4. Uvicorn_ is an ASGI server based on ``uvloop`` and ``httptools``, with an
  5. emphasis on speed.
  6. Installing Uvicorn
  7. ==================
  8. You can install Uvicorn with ``pip``:
  9. .. code-block:: shell
  10. python -m pip install uvicorn
  11. Running Django in Uvicorn
  12. =========================
  13. When Uvicorn is installed, a ``uvicorn`` command is available which runs ASGI
  14. applications. Uvicorn needs to be called with the location of a module
  15. containing an ASGI application object, followed by what the application is
  16. called (separated by a colon).
  17. For a typical Django project, invoking Uvicorn would look like:
  18. .. code-block:: shell
  19. python -m uvicorn myproject.asgi:application
  20. This will start one process listening on ``127.0.0.1:8000``. It requires that
  21. your project be on the Python path; to ensure that run this command from the
  22. same directory as your ``manage.py`` file.
  23. In development mode, you can add ``--reload`` to cause the server to reload any
  24. time a file is changed on disk.
  25. For more advanced usage, please read the `Uvicorn documentation <Uvicorn_>`_.
  26. Deploying Django using Uvicorn and Gunicorn
  27. ===========================================
  28. Gunicorn_ is a robust web server that implements process monitoring and automatic
  29. restarts. This can be useful when running Uvicorn in a production environment.
  30. To install Uvicorn and Gunicorn, use the following:
  31. .. code-block:: shell
  32. python -m pip install uvicorn uvicorn-worker gunicorn
  33. Then start Gunicorn using the Uvicorn worker class like this:
  34. .. code-block:: shell
  35. python -m gunicorn myproject.asgi:application -k uvicorn_worker.UvicornWorker
  36. .. _Uvicorn: https://www.uvicorn.org/
  37. .. _Gunicorn: https://gunicorn.org/