index.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. PyWebIO
  2. ==========
  3. PyWebIO provides a diverse set of imperative functions to obtain user input and output content on the browser,
  4. turning the browser into a "rich text terminal", and can be used to build simple web applications or browser-based
  5. GUI applications. Using PyWebIO, developers can write applications just like writing terminal scripts
  6. (interaction based on input and print function), without the need to have knowledge of HTML and JS.
  7. PyWebIO can also be easily integrated into existing Web services.
  8. PyWebIO is very suitable for quickly building applications that do not require complex UI.
  9. Features
  10. ------------
  11. - Use synchronization instead of callback-based method to get input
  12. - Non-declarative layout, simple and efficient
  13. - Less intrusive: old script code can be transformed into a Web service only by modifying the input and output operation
  14. - Support integration into existing web services, currently supports Flask, Django, Tornado, aiohttp and FastAPI(Starlette) framework
  15. - Support for ``asyncio`` and coroutine
  16. - Support data visualization with third-party libraries
  17. Installation
  18. --------------
  19. Stable version::
  20. pip3 install -U pywebio
  21. Development version::
  22. pip3 install -U https://code.aliyun.com/wang0618/pywebio/repository/archive.zip
  23. **Prerequisites**: PyWebIO requires Python 3.5.2 or newer
  24. .. _hello_word:
  25. Hello, world
  26. --------------
  27. Here is a simple PyWebIO script to calculate the `BMI <https://en.wikipedia.org/wiki/Body_mass_index>`_ ::
  28. # A simple script to calculate BMI
  29. from pywebio.input import input, FLOAT
  30. from pywebio.output import put_text
  31. def bmi():
  32. height = input("Input your height(cm):", type=FLOAT)
  33. weight = input("Input your weight(kg):", type=FLOAT)
  34. BMI = weight / (height / 100) ** 2
  35. top_status = [(16, 'Severely underweight'), (18.5, 'Underweight'),
  36. (25, 'Normal'), (30, 'Overweight'),
  37. (35, 'Moderately obese'), (float('inf'), 'Severely obese')]
  38. for top, status in top_status:
  39. if BMI <= top:
  40. put_text('Your BMI: %.1f. Category: %s' % (BMI, status))
  41. break
  42. if __name__ == '__main__':
  43. bmi()
  44. This is just a very simple script if you ignore PyWebIO, but after using the input and output functions provided by PyWebIO,
  45. you can interact with the code in the browser:
  46. .. image:: /assets/demo.*
  47. :width: 450px
  48. :align: center
  49. In the last line of the above code, changing the function call ``bmi()`` to
  50. `pywebio.start_server(bmi, port=80) <pywebio.platform.tornado.start_server>` will start a bmi web service on port 80
  51. ( :demo_host:`online Demo </bmi>` ).
  52. If you want to integrate the ``bmi()`` service into an existing web framework, you can visit
  53. :ref:`Integration with a web framework <integration_web_framework>` section of this document.
  54. Documentation
  55. -------------
  56. This documentation is also available in `PDF and Epub formats <https://readthedocs.org/projects/pywebio/downloads/>`_.
  57. .. toctree::
  58. :maxdepth: 2
  59. :caption: Manual
  60. guide
  61. input
  62. output
  63. session
  64. platform
  65. pin
  66. advanced
  67. libraries_support
  68. .. toctree::
  69. :titlesonly:
  70. FAQ
  71. releases
  72. .. toctree::
  73. :maxdepth: 2
  74. :caption: Implement Doc
  75. spec
  76. Indices and tables
  77. ----------------------
  78. * :ref:`genindex`
  79. * :ref:`modindex`
  80. * :ref:`search`
  81. Discussion and support
  82. ----------------------
  83. * Need help when use PyWebIO? Make a new discussion on `Github Discussions <https://github.com/wang0618/PyWebIO/discussions>`_.
  84. * Report bugs on the `GitHub issue <https://github.com/wang0618/pywebio/issues>`_.