uvicorn.txt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ==============================
  2. How to use Django with Uvicorn
  3. ==============================
  4. .. highlight:: bash
  5. Uvicorn_ is an ASGI server based on ``uvloop`` and ``httptools``, with an
  6. emphasis on speed.
  7. Installing Uvicorn
  8. ==================
  9. You can install Uvicorn with ``pip``::
  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. python -m uvicorn myproject.asgi:application
  19. This will start one process listening on ``127.0.0.1:8000``. It requires that
  20. your project be on the Python path; to ensure that run this command from the
  21. same directory as your ``manage.py`` file.
  22. In development mode, you can add ``--reload`` to cause the server to reload any
  23. time a file is changed on disk.
  24. For more advanced usage, please read the `Uvicorn documentation <Uvicorn_>`_.
  25. Deploying Django using Uvicorn and Gunicorn
  26. ===========================================
  27. Gunicorn_ is a robust web server that implements process monitoring and automatic
  28. restarts. This can be useful when running Uvicorn in a production environment.
  29. To install Uvicorn and Gunicorn, use the following::
  30. python -m pip install uvicorn gunicorn
  31. Then start Gunicorn using the Uvicorn worker class like this::
  32. python -m gunicorn myproject.asgi:application -k uvicorn.workers.UvicornWorker
  33. .. _Uvicorn: https://www.uvicorn.org/
  34. .. _Gunicorn: https://gunicorn.org/