__init__.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. .. autofunction:: pywebio.platform.path_deploy
  11. .. autofunction:: pywebio.platform.path_deploy_http
  12. Application Deploy
  13. --------------------
  14. The ``start_server()`` functions can start a Python Web server and serve given PyWebIO applications on it.
  15. The ``webio_handler()`` and ``webio_view()`` functions can be used to integrate PyWebIO applications into existing Python Web project.
  16. .. versionchanged:: 1.1
  17. Added the ``cdn`` parameter in ``start_server()``, ``webio_handler()`` and ``webio_view()``.
  18. .. versionchanged:: 1.2
  19. Added the ``static_dir`` parameter in ``start_server()``.
  20. Tornado support
  21. ^^^^^^^^^^^^^^^^^^^^
  22. There are two protocols (WebSocket and HTTP) can be used to communicates with the browser:
  23. WebSocket
  24. '''''''''''''
  25. .. autofunction:: pywebio.platform.tornado.start_server
  26. .. autofunction:: pywebio.platform.tornado.webio_handler
  27. HTTP
  28. '''''''''''''
  29. .. autofunction:: pywebio.platform.tornado_http.start_server
  30. .. autofunction:: pywebio.platform.tornado_http.webio_handler
  31. Flask support
  32. ^^^^^^^^^^^^^^^^^^^^
  33. 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``.
  34. You can install it with the following command::
  35. pip3 install -U flask>=0.10
  36. .. autofunction:: pywebio.platform.flask.webio_view
  37. .. autofunction:: pywebio.platform.flask.start_server
  38. Django support
  39. ^^^^^^^^^^^^^^^^^^^^
  40. 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``.
  41. You can install it with the following command::
  42. pip3 install -U django>=2.2
  43. .. autofunction:: pywebio.platform.django.webio_view
  44. .. autofunction:: pywebio.platform.django.start_server
  45. aiohttp support
  46. ^^^^^^^^^^^^^^^^^^^^
  47. 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``.
  48. You can install it with the following command::
  49. pip3 install -U aiohttp>=3.1
  50. .. autofunction:: pywebio.platform.aiohttp.webio_handler
  51. .. autofunction:: pywebio.platform.aiohttp.start_server
  52. Other
  53. --------------
  54. .. autofunction:: pywebio.platform.seo
  55. .. autofunction:: pywebio.platform.run_event_loop
  56. """
  57. from .httpbased import run_event_loop
  58. from .tornado import start_server
  59. from .utils import seo
  60. from .path_deploy import path_deploy_http, path_deploy