__init__.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. r"""
  2. The ``platform`` module provides support for deploying PyWebIO applications in different web frameworks.
  3. .. seealso::
  4. * :ref:`Integration with Web Framework <integration_web_framework>`
  5. * :ref:`Server mode and Script mode <server_and_script_mode>`
  6. Directory Deploy
  7. -----------------
  8. You can use ``path_deploy()`` or ``path_deploy_http()`` to deploy the PyWebIO applications from a directory.
  9. You can access the application by using the file path as the URL.
  10. Note that users can't view and access files or folders whose name begin with the underscore in this directory.
  11. .. autofunction:: pywebio.platform.path_deploy
  12. .. autofunction:: pywebio.platform.path_deploy_http
  13. Application Deploy
  14. --------------------
  15. The ``start_server()`` functions can start a Python Web server and serve given PyWebIO applications on it.
  16. The ``webio_handler()`` and ``webio_view()`` functions can be used to integrate PyWebIO applications into existing Python Web project.
  17. The ``wsgi_app()`` and ``asgi_app()`` is used to get the WSGI or ASGI app for running PyWebIO applications.
  18. This is helpful when you don't want to start server with the Web framework built-in's.
  19. For example, you want to use other WSGI server, or you are deploying app in a cloud environment.
  20. Note that only Flask, Django and FastApi backend support it.
  21. .. versionchanged:: 1.1
  22. Added the ``cdn`` parameter in ``start_server()``, ``webio_handler()`` and ``webio_view()``.
  23. .. versionchanged:: 1.2
  24. Added the ``static_dir`` parameter in ``start_server()``.
  25. .. versionchanged:: 1.3
  26. Added the ``wsgi_app()`` and ``asgi_app()``.
  27. Tornado support
  28. ^^^^^^^^^^^^^^^^^^^^
  29. There are two protocols (WebSocket and HTTP) can be used to communicates with the browser:
  30. WebSocket
  31. '''''''''''''
  32. .. autofunction:: pywebio.platform.tornado.start_server
  33. .. autofunction:: pywebio.platform.tornado.webio_handler
  34. HTTP
  35. '''''''''''''
  36. .. autofunction:: pywebio.platform.tornado_http.start_server
  37. .. autofunction:: pywebio.platform.tornado_http.webio_handler
  38. Flask support
  39. ^^^^^^^^^^^^^^^^^^^^
  40. When using the Flask as PyWebIO backend server, you need to install Flask by yourself and make sure the version is not less than ``0.10``.
  41. You can install it with the following command::
  42. pip3 install -U flask>=0.10
  43. .. autofunction:: pywebio.platform.flask.webio_view
  44. .. autofunction:: pywebio.platform.flask.wsgi_app
  45. .. autofunction:: pywebio.platform.flask.start_server
  46. Django support
  47. ^^^^^^^^^^^^^^^^^^^^
  48. When using the Django as PyWebIO backend server, you need to install Django by yourself and make sure the version is not less than ``2.2``.
  49. You can install it with the following command::
  50. pip3 install -U django>=2.2
  51. .. autofunction:: pywebio.platform.django.webio_view
  52. .. autofunction:: pywebio.platform.django.wsgi_app
  53. .. autofunction:: pywebio.platform.django.start_server
  54. aiohttp support
  55. ^^^^^^^^^^^^^^^^^^^^
  56. When using the aiohttp as PyWebIO backend server, you need to install aiohttp by yourself and make sure the version is not less than ``3.1``.
  57. You can install it with the following command::
  58. pip3 install -U aiohttp>=3.1
  59. .. autofunction:: pywebio.platform.aiohttp.webio_handler
  60. .. autofunction:: pywebio.platform.aiohttp.start_server
  61. FastAPI/Starlette support
  62. ^^^^^^^^^^^^^^^^^^^^^^^^^
  63. When using the FastAPI/Starlette as PyWebIO backend server, you need to install ``fastapi`` or ``starlette`` by yourself.
  64. Also other dependency packages are required. You can install them with the following command::
  65. pip3 install -U fastapi starlette uvicorn aiofiles websockets
  66. .. autofunction:: pywebio.platform.fastapi.webio_routes
  67. .. autofunction:: pywebio.platform.fastapi.asgi_app
  68. .. autofunction:: pywebio.platform.fastapi.start_server
  69. Other
  70. --------------
  71. .. autofunction:: pywebio.platform.seo
  72. .. autofunction:: pywebio.platform.run_event_loop
  73. """
  74. from .httpbased import run_event_loop
  75. from .tornado import start_server
  76. from .utils import seo
  77. from .path_deploy import path_deploy_http, path_deploy