PyWebIO - Write interactive web app in script way.


Shell IO

https://tecadmin.net/prompt-user-input-in-linux-shell-script/#

Take Input on Termianl

Let’s begin with input directly on terminal. Open a terminal on your system and type:

read x 

Here read is the Linux command and “x” is the variable, where input value will be stored.

Hit enter after typing the above command. You will see a blank line without a prompt. It means the shell is waiting for your input. Type some text and hit enter button. You will find the prompt again.

Now, verify that the input value is stored in a defined variable. To confirm it, print the variable value with the echo command.

echo $x

There is no need to define any data type for variables. Shell automatically adjusts the type based on the user input.

Lets’ go with a sample shell script to take user input.

 

PyWebIO

https://github.com/pywebio/PyWebIO

https://pywebio.readthedocs.io/en/latest/

 

調用python函數的方式,獲取用戶輸入 和 輸出到瀏覽器。(體驗類似 shell )

構建簡單的web應用 或者 基於瀏覽器的 GUI 應用, 不需要HTML JS知識。

 

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 demo PyWebIO input demo


 

特征:

  • 同步模式讀取輸出
  • 布局內置,不用設置
  • 更少的入侵, 修改已有代碼,只需要關注輸入和輸出的替換,可完成代碼改造
  • 支持繼承到已有web框架
  • 支持 異步 和 協程
  • 支持數據可視化

 

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.

 

DEMO

https://pywebio-demos.pywebio.online/

基本demo

  • BMI計算: 根據身高體重計算BMI指數
  • 聊天室: 和當前所有在線的人聊天 (不到90行代碼實現)
  • Markdown實時預覽: 可以實時預覽的在線Markdown編輯器 (不到40行代碼實現)
  • 在線五子棋游戲: 多人協作對戰的五子棋游戲 (不到100行代碼實現)
  • 輸入演示: 演示PyWebIO輸入模塊的用法
  • 輸出演示: 演示PyWebIO輸出模塊的用法
  • 更多Demo請見文檔中示例代碼的在線Demo

數據可視化demo

PyWebIO還支持使用第三方庫進行數據可視化

  • 使用bokeh進行數據可視化 demos
  • 使用plotly進行數據可視化 demos
  • 使用pyecharts創建基於Echarts的圖表 demos
  • 使用pyg2plot創建基於G2Plot的圖表 demos
  • 使用cutecharts.py創建卡通風格圖表 demos

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM