pywebio /PyWebIO

Write interactive web app in script way.

★ 4,809⑂ 384👁 53⑃ 67● 251▤ 0
PythonCreated 2020-02-29pywebio.readthedocs.io
+0
Daily
+0
Weekly
-4
Monthly
4,809
stars
384
forks
53
watchers
67
prs
251
issues
0
releases

README

PyWebIO

    Write interactive web app in script way.


    
        
    
    
        
    
    
        
    
    
        
    
    
        
    
    
        %3D%203.5.2-brightgreen" alt="Python Version"
    
    
    
        
    
    
    [Document] | [Demos] | [Playground] | [Why PyWebIO?]


English | 中文

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 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.


    
    



Features:

- Use synchronization instead of a callback-based method to get input
- Non-declarative layout, simple and efficient
- Less intrusive: old script code can be transformed into a Web application only by modifying the input and output operation
- Support integration into existing web services, currently supports Flask, Django, Tornado, aiohttp, FastAPI framework
- Support for asyncio and coroutine
- Support data visualization with third-party libraries, e.g., plotly, bokeh, pyecharts.

 Installation

Stable version:

bash
pip3 install -U pywebio


Development version:
bash
pip3 install -U https://github.com/pywebio/PyWebIO/archive/dev-release.zip


Prerequisites: PyWebIO requires Python 3.5.2 or newer

 Quickstart

Hello, world

Here is a simple PyWebIO script to calculate the BMI:

python
from pywebio.input import input, FLOAT
from pywebio.output import put_text

def bmi():
    height = input("Your Height(cm):", type=FLOAT)
    weight = input("Your Weight(kg):", type=FLOAT)

    BMI = weight / (height / 100)  2

    top_status = [(14.9, 'Severely underweight'), (18.4, 'Underweight'),
                  (22.9, 'Normal'), (27.5, 'Overweight'),
                  (40.0, 'Moderately obese'), (float('inf'), 'Severely obese')]

    for top, status in top_status:
        if BMI 
    
        
    


Serve as web service

The above BMI program will exit immediately after the calculation, you can use pywebio.start_server() to publish the bmi() function as a web application:

python
from pywebio import start_server
from pywebio.input import input, FLOAT
from pywebio.output import put_text

def bmi():  bmi() keep the same
    ...  

if __name__ == '__main__':
    start_server(bmi, port=80)


Integration with web framework

To integrate a PyWebIO application into Tornado, all you need is to add a RequestHandler to the existing Tornado application:

python
import tornado.ioloop
import tornado.web
from pywebio.platform.tornado import webio_handler

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

if __name__ == "__main__":
    application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/bmi", webio_handler(bmi)),   bmi is the 

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON