{"id":13460117,"url":"https://github.com/pywebio/PyWebIO","last_synced_at":"2025-03-24T18:33:08.228Z","repository":{"id":37407882,"uuid":"243948277","full_name":"pywebio/PyWebIO","owner":"pywebio","description":"Write interactive web app in script way.","archived":false,"fork":false,"pushed_at":"2024-07-18T06:36:48.000Z","size":11745,"stargazers_count":4523,"open_issues_count":33,"forks_count":384,"subscribers_count":54,"default_branch":"dev","last_synced_at":"2024-10-29T15:01:54.097Z","etag":null,"topics":["pywebio"],"latest_commit_sha":null,"homepage":"https://pywebio.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pywebio.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-29T10:28:10.000Z","updated_at":"2024-10-29T04:43:29.000Z","dependencies_parsed_at":"2024-02-16T05:23:04.260Z","dependency_job_id":"76a59f90-6878-47d8-8f4f-bfc185becc7f","html_url":"https://github.com/pywebio/PyWebIO","commit_stats":{"total_commits":933,"total_committers":18,"mean_commits":"51.833333333333336","dds":0.04608788853161838,"last_synced_commit":"e810dc45494348e27a5a4e1148985c619bed9a91"},"previous_names":["wang0618/pywebio"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywebio%2FPyWebIO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywebio%2FPyWebIO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywebio%2FPyWebIO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywebio%2FPyWebIO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pywebio","download_url":"https://codeload.github.com/pywebio/PyWebIO/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245066675,"owners_count":20555427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pywebio"],"created_at":"2024-07-31T10:00:35.841Z","updated_at":"2025-03-24T18:33:07.521Z","avatar_url":"https://github.com/pywebio.png","language":"Python","funding_links":[],"categories":["Python","ScriptWebTool\u0026\u0026TUI","Web UI","语言资源库"],"sub_categories":["python"],"readme":"\u003ch1 align=\"center\" name=\"pywebio-zh\"\u003ePyWebIO\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003cem\u003eWrite interactive web app in script way.\u003c/em\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://percy.io/pywebio/pywebio\"\u003e\n        \u003cimg src=\"https://percy.io/static/images/percy-badge.svg\" alt=\"Percy visual test\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/pywebio/PyWebIO\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/pywebio/PyWebIO/branch/dev/graph/badge.svg?token=YWH3WC828H\" alt=\"Code coverage\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.jsdelivr.com/package/gh/wang0618/PyWebIO-assets\"\u003e\n        \u003cimg src=\"https://data.jsdelivr.com/v1/package/gh/wang0618/PyWebIO-assets/badge?style=rounded\" alt=\"Jsdelivr hit count\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pywebio.readthedocs.io/zh_CN/latest/?badge=latest\"\u003e\n        \u003cimg src=\"https://readthedocs.org/projects/pywebio/badge/?version=latest\" alt=\"Documentation Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/PyWebIO/\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/pywebio?colorB=brightgreen\" alt=\"Package version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/PyWebIO/\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/python-\u003e%3D%203.5.2-brightgreen\" alt=\"Python Version\"\u003e\n    \u003c/a\u003e\n    \u003cbr/\u003e\n    \u003ca href=\"https://github.com/wang0618/PyWebIO/blob/master/LICENSE\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/license/wang0618/PyWebIO.svg\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003cbr/\u003e\n    \u003ca href=\"https://pywebio.readthedocs.io/zh_CN/latest/\"\u003e[Document]\u003c/a\u003e | \u003ca href=\"http://pywebio-demos.pywebio.online/\"\u003e[Demos]\u003c/a\u003e | \u003ca href=\"https://play.pywebio.online\"\u003e[Playground]\u003c/a\u003e | \u003ca href=\"https://github.com/wang0618/PyWebIO/wiki/%5B%E4%B8%AD%E6%96%87%5D-Why-PyWebIO%3F\"\u003e[Why PyWebIO?]\u003c/a\u003e\n\u003c/p\u003e\n\n[English](README.md) | [中文](README-zh.md)\n\nPyWebIO提供了一系列命令式的交互函数来在浏览器上获取用户输入和进行输出，将浏览器变成了一个“富文本终端”，可以用于构建简单的Web应用或基于浏览器的GUI应用。\nPyWebIO还可以方便地整合进现有的Web服务，让你不需要编写HTML和JS代码，就可以构建出具有良好可用性的应用。\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/output_demo.gif\" alt=\"PyWebIO output demo\" width='609px'/\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/input_demo.gif\" alt=\"PyWebIO input demo\" width='609px'/\u003e\n\u003c/p\u003e\n\n\n功能特性：\n\n- 使用同步而不是基于回调的方式获取输入，代码编写逻辑更自然\n- 非声明式布局，布局方式简单高效\n- 代码侵入性小，旧脚本代码仅需修改输入输出逻辑便可改造为Web服务\n- 支持整合到现有的Web服务，目前支持与Flask、Django、Tornado、aiohttp、FastAPI框架集成\n- 同时支持基于线程的执行模型和基于协程的执行模型\n- 支持结合第三方库实现数据可视化\n\n## Installation\n\n稳定版安装:\n\n```bash\npip3 install -U pywebio\n```\n\n开发版安装:\n```bash\npip3 install -U https://github.com/pywebio/PyWebIO/archive/dev-release.zip\n```\n\n**系统要求**: PyWebIO要求 Python 版本在 3.5.2 及以上\n\n## Quickstart\n\n**Hello, world**\n\n这是一个使用PyWebIO计算 [BMI指数](https://en.wikipedia.org/wiki/Body_mass_index) 的脚本:\n\n```python\nfrom pywebio.input import input, FLOAT\nfrom pywebio.output import put_text\n\ndef bmi():\n    height = input(\"请输入你的身高(cm)：\", type=FLOAT)\n    weight = input(\"请输入你的体重(kg)：\", type=FLOAT)\n\n    BMI = weight / (height / 100) ** 2\n\n    top_status = [(14.9, '极瘦'), (18.4, '偏瘦'),\n                  (22.9, '正常'), (27.5, '过重'),\n                  (40.0, '肥胖'), (float('inf'), '非常肥胖')]\n\n    for top, status in top_status:\n        if BMI \u003c= top:\n            put_text('你的 BMI 值: %.1f，身体状态：%s' % (BMI, status))\n            break\n\nif __name__ == '__main__':\n    bmi()\n```\n\n\n如果没有使用PyWebIO，这只是一个非常简单的脚本，而通过使用PyWebIO提供的输入输出函数，你可以在浏览器中与代码进行交互 [[demo]](http://pywebio-demos.pywebio.online/bmi)：\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://pywebio-demos.pywebio.online/?pywebio_api=bmi\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/demo_zh.gif\" alt=\"PyWebIO demo\" width=\"400px\"/\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n**作为Web服务提供**\n\n上文BMI程序会在计算完毕后立刻退出，可以使用 [`pywebio.start_server()`](https://pywebio.readthedocs.io/zh_CN/latest/platform.html#pywebio.platform.tornado.start_server) 将 `bmi()` 函数作为Web服务提供：\n\n```python\nfrom pywebio import start_server\nfrom pywebio.input import input, FLOAT\nfrom pywebio.output import put_text\n\ndef bmi():  # bmi() 函数内容不变\n    ...  \n\nif __name__ == '__main__':\n    start_server(bmi, port=80)\n```\n\n**与现有Web框架整合**\n\nTornado应用整合：仅需在现有的Tornado应用中添加一个 `RequestHandler` ，就可以将PyWebIO应用整合进Tornado Web服务中\n\n```python\nimport tornado.ioloop\nimport tornado.web\nfrom pywebio.platform.tornado import webio_handler\n\nclass MainHandler(tornado.web.RequestHandler):\n    def get(self):\n        self.write(\"Hello, world\")\n\nif __name__ == \"__main__\":\n    application = tornado.web.Application([\n        (r\"/\", MainHandler),\n        (r\"/bmi\", webio_handler(bmi)),  # bmi 即为上文计算BMI指数的函数\n    ])\n    application.listen(port=80, address='localhost')\n    tornado.ioloop.IOLoop.current().start()\n```\n\n在 `http://localhost/bmi` 页面上就可以计算BMI了。\n\n与其他Web框架整合请见[文档](https://pywebio.readthedocs.io/zh_CN/latest/advanced.html#integration-with-web-framework)\n\n## Demos\n\n - [基本demo](http://pywebio-demos.pywebio.online/) : 包含PyWebIO基本输入输出演示和使用PyWebIO编写的小应用\n - [数据可视化demo](http://pywebio-charts.pywebio.online/) : 使用 bokeh、plotly、pyecharts 等库进行数据可视化\n\n## Links\n\n* 使用手册和实现文档见 [pywebio.readthedocs.io](https://pywebio.readthedocs.io/zh_CN/latest/)\n* [PyWebIO Playground](https://play.pywebio.online/): 在线编辑、运行和分享PyWebIO代码\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpywebio%2FPyWebIO","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpywebio%2FPyWebIO","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpywebio%2FPyWebIO/lists"}