Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Write interactive web app in script way.

License

NotificationsYou must be signed in to change notification settings

pywebio/PyWebIO

Repository files navigation

Write interactive web app in script way.

Percy visual testCode coverageJsdelivr hit countDocumentation StatusPackage versionPython Version
License
[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.

PyWebIO output demoPyWebIO input demo

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 forasyncio and coroutine
  • Support data visualization with third-party libraries, e.g.,plotly,bokeh,pyecharts.

Installation

Stable version:

pip3 install -U pywebio

Development version:

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 theBMI:

frompywebio.inputimportinput,FLOATfrompywebio.outputimportput_textdefbmi():height=input("Your Height(cm):",type=FLOAT)weight=input("Your Weight(kg):",type=FLOAT)BMI=weight/ (height/100)**2top_status= [(14.9,'Severely underweight'), (18.4,'Underweight'),                  (22.9,'Normal'), (27.5,'Overweight'),                  (40.0,'Moderately obese'), (float('inf'),'Severely obese')]fortop,statusintop_status:ifBMI<=top:put_text('Your BMI: %.1f, category: %s'% (BMI,status))breakif__name__=='__main__':bmi()

This is just a very simple script if you ignore PyWebIO, but using the input and output functions provided by PyWebIO, you can interact with the code in the browser[demo]:

PyWebIO demo

Serve as web service

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

frompywebioimportstart_serverfrompywebio.inputimportinput,FLOATfrompywebio.outputimportput_textdefbmi():# 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 aRequestHandler to the existing Tornado application:

importtornado.ioloopimporttornado.webfrompywebio.platform.tornadoimportwebio_handlerclassMainHandler(tornado.web.RequestHandler):defget(self):self.write("Hello, world")if__name__=="__main__":application=tornado.web.Application([        (r"/",MainHandler),        (r"/bmi",webio_handler(bmi)),# bmi is the same function as above    ])application.listen(port=80,address='localhost')tornado.ioloop.IOLoop.current().start()

Now, you can openhttp://localhost/bmi for BMI calculation.

For integration with other web frameworks, please refer todocument.

Demos

  • Basic demo : PyWebIO basic input and output demos and some small applications written using PyWebIO.
  • Data visualization demo : Data visualization with the third-party libraries, e.g.,plotly,bokeh,pyecharts.

Links

About

Write interactive web app in script way.

Topics

Resources

License

Stars

Watchers

Forks

Contributors17


[8]ページ先頭

©2009-2025 Movatter.jp