index.rst 3.5 KB

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