pywebio


Namepywebio JSON
Version 1.8.3 PyPI version JSON
download
home_pagehttps://pywebio.readthedocs.io
SummaryWrite interactive web app in script way.
upload_time2023-10-30 13:40:38
maintainer
docs_urlNone
authorWangWeimin
requires_python>=3.5.2
licenseMIT
keywords
VCS
bugtrack_url
requirements tornado user-agents flask django aiohttp starlette uvicorn aiofiles bokeh pandas cutecharts pyecharts plotly Pillow selenium percy-python-selenium coverage Jinja2 sphinx sphinx-tabs sphinx-rtd-theme sphinx-toolbox sphinx-intl pywebio_battery numpy matplotlib openai
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center" name="pywebio-en">PyWebIO</h1>
<p align="center">
    <em>Write interactive web app in script way.</em>
</p>
<p align="center">
    <a href="https://percy.io/pywebio/pywebio">
        <img src="https://percy.io/static/images/percy-badge.svg" alt="Percy visual test">
    </a>
    <a href="https://codecov.io/gh/pywebio/PyWebIO">
        <img src="https://codecov.io/gh/pywebio/PyWebIO/branch/dev/graph/badge.svg?token=YWH3WC828H" alt="Code coverage"/>
    </a>
    <a href="https://www.jsdelivr.com/package/gh/wang0618/PyWebIO-assets">
        <img src="https://data.jsdelivr.com/v1/package/gh/wang0618/PyWebIO-assets/badge?style=rounded" alt="Jsdelivr hit count"/>
    </a>
    <a href="https://pywebio.readthedocs.io/zh_CN/latest/?badge=latest">
        <img src="https://readthedocs.org/projects/pywebio/badge/?version=latest" alt="Documentation Status">
    </a>
    <a href="https://pypi.org/project/PyWebIO/">
        <img src="https://img.shields.io/pypi/v/pywebio?colorB=brightgreen" alt="Package version">
    </a>
    <a href="https://pypi.org/project/PyWebIO/">
        <img src="https://img.shields.io/badge/python->%3D%203.5.2-brightgreen" alt="Python Version">
    </a>
    <br/>
    <a href="https://github.com/wang0618/PyWebIO/blob/master/LICENSE">
        <img src="https://img.shields.io/github/license/wang0618/PyWebIO.svg" alt="License">
    </a>
    <br/>
    <a href="https://pywebio.readthedocs.io">[Document]</a> | <a href="http://pywebio-demos.pywebio.online/">[Demos]</a> | <a href="https://play.pywebio.online">[Playground]</a> | <a href="https://github.com/wang0618/PyWebIO/wiki/Why-PyWebIO%3F">[Why PyWebIO?]</a>
</p>

[English](README.md) | [中文](README-zh.md)

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.

<p align="center">
    <img src="https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/output_demo.gif" alt="PyWebIO output demo" width='609px'/>
    <img src="https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/input_demo.gif" alt="PyWebIO input demo" width='609px'/>
</p>


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](https://en.wikipedia.org/wiki/Body_mass_index):

```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 <= 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 using the input and output functions provided by PyWebIO, you can interact with the code in the browser [[demo]](http://pywebio-demos.pywebio.online/bmi):

<p align="center">
    <a href="http://pywebio-demos.pywebio.online/?pywebio_api=bmi">
        <img src="https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/demo.gif" alt="PyWebIO demo" width="400px"/>
    </a>
</p>

**Serve as web service**

The above BMI program will exit immediately after the calculation, you can use [`pywebio.start_server()`](https://pywebio.readthedocs.io/en/latest/platform.html#pywebio.platform.tornado.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 same function as above
    ])
    application.listen(port=80, address='localhost')
    tornado.ioloop.IOLoop.current().start()
```

Now, you can open `http://localhost/bmi` for BMI calculation.

For integration with other web frameworks, please refer to [document](https://pywebio.readthedocs.io/en/latest/advanced.html#integration-with-web-framework).

## Demos

 - [Basic demo](http://pywebio-demos.pywebio.online/) : PyWebIO basic input and output demos and some small applications written using PyWebIO.
 - [Data visualization demo](http://pywebio-charts.pywebio.online/) : Data visualization with the third-party libraries, e.g., `plotly`, `bokeh`, `pyecharts`.

## Links

* Document [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
* [PyWebIO Playground](https://play.pywebio.online/): Edit, Run, Share PyWebIO Code Online
            

Raw data

            {
    "_id": null,
    "home_page": "https://pywebio.readthedocs.io",
    "name": "pywebio",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5.2",
    "maintainer_email": "",
    "keywords": "",
    "author": "WangWeimin",
    "author_email": "wang0.618@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/99/06/0c54f4809ca86c3ff1496a131902216d647442d18e5d212c7150ebf42f65/pywebio-1.8.3.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\" name=\"pywebio-en\">PyWebIO</h1>\n<p align=\"center\">\n    <em>Write interactive web app in script way.</em>\n</p>\n<p align=\"center\">\n    <a href=\"https://percy.io/pywebio/pywebio\">\n        <img src=\"https://percy.io/static/images/percy-badge.svg\" alt=\"Percy visual test\">\n    </a>\n    <a href=\"https://codecov.io/gh/pywebio/PyWebIO\">\n        <img src=\"https://codecov.io/gh/pywebio/PyWebIO/branch/dev/graph/badge.svg?token=YWH3WC828H\" alt=\"Code coverage\"/>\n    </a>\n    <a href=\"https://www.jsdelivr.com/package/gh/wang0618/PyWebIO-assets\">\n        <img src=\"https://data.jsdelivr.com/v1/package/gh/wang0618/PyWebIO-assets/badge?style=rounded\" alt=\"Jsdelivr hit count\"/>\n    </a>\n    <a href=\"https://pywebio.readthedocs.io/zh_CN/latest/?badge=latest\">\n        <img src=\"https://readthedocs.org/projects/pywebio/badge/?version=latest\" alt=\"Documentation Status\">\n    </a>\n    <a href=\"https://pypi.org/project/PyWebIO/\">\n        <img src=\"https://img.shields.io/pypi/v/pywebio?colorB=brightgreen\" alt=\"Package version\">\n    </a>\n    <a href=\"https://pypi.org/project/PyWebIO/\">\n        <img src=\"https://img.shields.io/badge/python->%3D%203.5.2-brightgreen\" alt=\"Python Version\">\n    </a>\n    <br/>\n    <a href=\"https://github.com/wang0618/PyWebIO/blob/master/LICENSE\">\n        <img src=\"https://img.shields.io/github/license/wang0618/PyWebIO.svg\" alt=\"License\">\n    </a>\n    <br/>\n    <a href=\"https://pywebio.readthedocs.io\">[Document]</a> | <a href=\"http://pywebio-demos.pywebio.online/\">[Demos]</a> | <a href=\"https://play.pywebio.online\">[Playground]</a> | <a href=\"https://github.com/wang0618/PyWebIO/wiki/Why-PyWebIO%3F\">[Why PyWebIO?]</a>\n</p>\n\n[English](README.md) | [\u4e2d\u6587](README-zh.md)\n\nPyWebIO 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.\n\n<p align=\"center\">\n    <img src=\"https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/output_demo.gif\" alt=\"PyWebIO output demo\" width='609px'/>\n    <img src=\"https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/input_demo.gif\" alt=\"PyWebIO input demo\" width='609px'/>\n</p>\n\n\nFeatures\uff1a\n\n- Use synchronization instead of a callback-based method to get input\n- Non-declarative layout, simple and efficient\n- Less intrusive: old script code can be transformed into a Web application only by modifying the input and output operation\n- Support integration into existing web services, currently supports Flask, Django, Tornado, aiohttp, FastAPI framework\n- Support for ``asyncio`` and coroutine\n- Support data visualization with third-party libraries, e.g., `plotly`, `bokeh`, `pyecharts`.\n\n## Installation\n\nStable version:\n\n```bash\npip3 install -U pywebio\n```\n\nDevelopment version:\n```bash\npip3 install -U https://github.com/pywebio/PyWebIO/archive/dev-release.zip\n```\n\n**Prerequisites**: PyWebIO requires Python 3.5.2 or newer\n\n## Quickstart\n\n**Hello, world**\n\nHere is a simple PyWebIO script to calculate the [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(\"Your Height(cm)\uff1a\", type=FLOAT)\n    weight = input(\"Your Weight(kg)\uff1a\", type=FLOAT)\n\n    BMI = weight / (height / 100) ** 2\n\n    top_status = [(14.9, 'Severely underweight'), (18.4, 'Underweight'),\n                  (22.9, 'Normal'), (27.5, 'Overweight'),\n                  (40.0, 'Moderately obese'), (float('inf'), 'Severely obese')]\n\n    for top, status in top_status:\n        if BMI <= top:\n            put_text('Your BMI: %.1f, category: %s' % (BMI, status))\n            break\n\nif __name__ == '__main__':\n    bmi()\n```\n\nThis 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]](http://pywebio-demos.pywebio.online/bmi):\n\n<p align=\"center\">\n    <a href=\"http://pywebio-demos.pywebio.online/?pywebio_api=bmi\">\n        <img src=\"https://raw.githubusercontent.com/wang0618/PyWebIO/dev/docs/assets/demo.gif\" alt=\"PyWebIO demo\" width=\"400px\"/>\n    </a>\n</p>\n\n**Serve as web service**\n\nThe above BMI program will exit immediately after the calculation, you can use [`pywebio.start_server()`](https://pywebio.readthedocs.io/en/latest/platform.html#pywebio.platform.tornado.start_server) to publish the `bmi()` function as a web application:\n\n```python\nfrom pywebio import start_server\nfrom pywebio.input import input, FLOAT\nfrom pywebio.output import put_text\n\ndef bmi(): # bmi() keep the same\n    ...  \n\nif __name__ == '__main__':\n    start_server(bmi, port=80)\n```\n\n**Integration with web framework**\n\nTo integrate a PyWebIO application into Tornado, all you need is to add a `RequestHandler` to the existing Tornado application:\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 is the same function as above\n    ])\n    application.listen(port=80, address='localhost')\n    tornado.ioloop.IOLoop.current().start()\n```\n\nNow, you can open `http://localhost/bmi` for BMI calculation.\n\nFor integration with other web frameworks, please refer to [document](https://pywebio.readthedocs.io/en/latest/advanced.html#integration-with-web-framework).\n\n## Demos\n\n - [Basic demo](http://pywebio-demos.pywebio.online/) : PyWebIO basic input and output demos and some small applications written using PyWebIO.\n - [Data visualization demo](http://pywebio-charts.pywebio.online/) : Data visualization with the third-party libraries, e.g., `plotly`, `bokeh`, `pyecharts`.\n\n## Links\n\n* Document [pywebio.readthedocs.io](https://pywebio.readthedocs.io)\n* [PyWebIO Playground](https://play.pywebio.online/): Edit, Run, Share PyWebIO Code Online",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Write interactive web app in script way.",
    "version": "1.8.3",
    "project_urls": {
        "Documentation": "https://pywebio.readthedocs.io",
        "Homepage": "https://pywebio.readthedocs.io",
        "Source": "https://github.com/wang0618/PyWebIO"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99060c54f4809ca86c3ff1496a131902216d647442d18e5d212c7150ebf42f65",
                "md5": "60c8e5e530a87dddfb1cca312367ee58",
                "sha256": "94589da5528958ed3a568d22fcb6892a372d234e41bc6a8169419dfff2d7b084"
            },
            "downloads": -1,
            "filename": "pywebio-1.8.3.tar.gz",
            "has_sig": false,
            "md5_digest": "60c8e5e530a87dddfb1cca312367ee58",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5.2",
            "size": 500898,
            "upload_time": "2023-10-30T13:40:38",
            "upload_time_iso_8601": "2023-10-30T13:40:38.794386Z",
            "url": "https://files.pythonhosted.org/packages/99/06/0c54f4809ca86c3ff1496a131902216d647442d18e5d212c7150ebf42f65/pywebio-1.8.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 13:40:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wang0618",
    "github_project": "PyWebIO",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "tornado",
            "specs": [
                [
                    ">=",
                    "5.0"
                ]
            ]
        },
        {
            "name": "user-agents",
            "specs": []
        },
        {
            "name": "flask",
            "specs": []
        },
        {
            "name": "django",
            "specs": []
        },
        {
            "name": "aiohttp",
            "specs": []
        },
        {
            "name": "starlette",
            "specs": []
        },
        {
            "name": "uvicorn",
            "specs": []
        },
        {
            "name": "aiofiles",
            "specs": []
        },
        {
            "name": "bokeh",
            "specs": []
        },
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "cutecharts",
            "specs": []
        },
        {
            "name": "pyecharts",
            "specs": []
        },
        {
            "name": "plotly",
            "specs": []
        },
        {
            "name": "Pillow",
            "specs": []
        },
        {
            "name": "selenium",
            "specs": [
                [
                    "==",
                    "3.*"
                ]
            ]
        },
        {
            "name": "percy-python-selenium",
            "specs": [
                [
                    "==",
                    "0.1.3"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": []
        },
        {
            "name": "Jinja2",
            "specs": [
                [
                    "==",
                    "3.0.3"
                ]
            ]
        },
        {
            "name": "sphinx",
            "specs": [
                [
                    "==",
                    "3.*"
                ]
            ]
        },
        {
            "name": "sphinx-tabs",
            "specs": []
        },
        {
            "name": "sphinx-rtd-theme",
            "specs": [
                [
                    "==",
                    "0.4.*"
                ]
            ]
        },
        {
            "name": "sphinx-toolbox",
            "specs": [
                [
                    "==",
                    "2.15.0"
                ]
            ]
        },
        {
            "name": "sphinx-intl",
            "specs": []
        },
        {
            "name": "pywebio_battery",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": []
        },
        {
            "name": "openai",
            "specs": []
        }
    ],
    "lcname": "pywebio"
}
        
Elapsed time: 0.25892s