__init__.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. .. versionchanged:: 1.1
  18. Added the ``cdn`` parameter in ``start_server()``, ``webio_handler()`` and ``webio_view()``.
  19. .. versionchanged:: 1.2
  20. Added the ``static_dir`` parameter in ``start_server()``.
  21. Tornado support
  22. ^^^^^^^^^^^^^^^^^^^^
  23. There are two protocols (WebSocket and HTTP) can be used to communicates with the browser:
  24. WebSocket
  25. '''''''''''''
  26. .. autofunction:: pywebio.platform.tornado.start_server
  27. .. autofunction:: pywebio.platform.tornado.webio_handler
  28. HTTP
  29. '''''''''''''
  30. .. autofunction:: pywebio.platform.tornado_http.start_server
  31. .. autofunction:: pywebio.platform.tornado_http.webio_handler
  32. Flask support
  33. ^^^^^^^^^^^^^^^^^^^^
  34. 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``.
  35. You can install it with the following command::
  36. pip3 install -U flask>=0.10
  37. .. autofunction:: pywebio.platform.flask.webio_view
  38. .. autofunction:: pywebio.platform.flask.start_server
  39. Django support
  40. ^^^^^^^^^^^^^^^^^^^^
  41. 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``.
  42. You can install it with the following command::
  43. pip3 install -U django>=2.2
  44. .. autofunction:: pywebio.platform.django.webio_view
  45. .. autofunction:: pywebio.platform.django.start_server
  46. aiohttp support
  47. ^^^^^^^^^^^^^^^^^^^^
  48. 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``.
  49. You can install it with the following command::
  50. pip3 install -U aiohttp>=3.1
  51. .. autofunction:: pywebio.platform.aiohttp.webio_handler
  52. .. autofunction:: pywebio.platform.aiohttp.start_server
  53. FastAPI/Starlette support
  54. ^^^^^^^^^^^^^^^^^^^^^^^^^
  55. When using the FastAPI/Starlette as PyWebIO backend server, you need to install ``fastapi`` or ``starlette`` by yourself.
  56. Also other dependency packages are required. You can install them with the following command::
  57. pip3 install -U fastapi starlette uvicorn aiofiles websockets
  58. .. autofunction:: pywebio.platform.fastapi.webio_routes
  59. .. autofunction:: pywebio.platform.fastapi.asgi_app
  60. .. autofunction:: pywebio.platform.fastapi.start_server
  61. Other
  62. --------------
  63. .. autofunction:: pywebio.platform.seo
  64. .. autofunction:: pywebio.platform.run_event_loop
  65. """
  66. from .httpbased import run_event_loop
  67. from .tornado import start_server
  68. from .utils import seo
  69. from .path_deploy import path_deploy_http, path_deploy