PyWebIO provides a series of imperative functions to obtain user input and output content 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 function), 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.
Use synchronization instead of callback-based method to get input
Non-declarative layout, simple and efficient
Less intrusive: old script code can be transformed into a Web service only by modifying the input and output operation
Support integration into existing web services, currently supports Flask, Django, Tornado, aiohttp and FastAPI(Starlette) framework
Support data visualization with third-party libraries
pip3 install -U pywebio
pip3 install -U https://code.aliyun.com/wang0618/pywebio/repository/archive.zip
Prerequisites: PyWebIO requires Python 3.5.2 or newer
Here is a simple PyWebIO script to calculate the BMI
# A simple script to calculate BMI from pywebio.input import input, FLOAT from pywebio.output import put_text def bmi(): height = input("Input your height(cm)：", type=FLOAT) weight = input("Input your weight(kg)：", type=FLOAT) BMI = weight / (height / 100) ** 2 top_status = [(16, 'Severely underweight'), (18.5, 'Underweight'), (25, 'Normal'), (30, 'Overweight'), (35, 'Moderately obese'), (float('inf'), 'Severely obese')] for top, status in top_status: if BMI <= top: put_text('Your BMI: %.1f. Category: %s' % (BMI, status)) break if __name__ == '__main__': bmi()
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:
If you want to integrate the
bmi() service into an existing web framework, you can visit
Integration with a web framework section of this document.
This documentation is also available in PDF and Epub formats.
- User’s guide
pywebio.input— Get input from web browser
pywebio.output— Make output to web browser
pywebio.session— More control to session
pywebio.platform— Deploy applications
pywebio.pin— Persistent input
- Advanced topic
- Libraries support