webview-python


Namewebview-python JSON
Version 0.99.16 PyPI version JSON
download
home_pageNone
SummaryPython bindings for the webview library, which completely follow deno_webview design and principles
upload_time2024-11-03 16:22:46
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Python Webview Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords webview gui desktop application html web
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Webview Python

[![Test - Windows](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml/badge.svg?branch=main&event=push&label=Windows)](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml)
[![Test - Linux](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml/badge.svg?branch=main&event=push&label=Linux)](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml)
[![Test - macOS](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml/badge.svg?branch=main&event=push&label=macOS)](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml)
[![PyPI version](https://badge.fury.io/py/webview_python.svg)](https://badge.fury.io/py/webview_python)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python Version](https://img.shields.io/pypi/pyversions/webview_python.svg)](https://pypi.org/project/webview_python/)

Python bindings for the webview library, allowing you to create desktop applications with web technologies.

## Installation

```bash
pip install webview_python
```

## Usage

### Display Inline HTML:

```python
from webview.webview import Webview
from urllib.parse import quote

html = """
<html>
<body>
<h1>Hello from Python Webview!</h1>
</body>
</html>
"""
webview = Webview()
webview.navigate(f"data:text/html,{quote(html)}")
webview.run()
```

### Load Local HTML File:

```python
from webview.webview import Webview
import os

webview = Webview()
current_dir = os.path.dirname(os.path.abspath(__file__))
html_path = os.path.join(current_dir, 'local.html')
webview.navigate(f"file://{html_path}")
webview.run()
```

### Load Remote URL:

```python
from webview.webview import Webview
webview = Webview()
webview.navigate("https://www.python.org")
webview.run()
```

### Python-JavaScript Bindings:

```python
from webview.webview import Webview, Size, SizeHint
from urllib.parse import quote

webview = Webview(debug=True)

# Python functions that can be called from JavaScript
def hello():
    webview.eval("updateFromPython('Hello from Python!')")
    return "Hello from Python!"

def add(a, b):
    return a + b

# Bind Python functions
webview.bind("hello", hello)
webview.bind("add", add)

# Configure window
webview.title = "Python-JavaScript Binding Demo"
webview.size = Size(640, 480, SizeHint.FIXED)

# Load HTML with JavaScript
html = """
<html>
<head>
    <title>Python-JavaScript Binding Demo</title>
    <script>
        async function callPython() {
            const result = await hello();
            document.getElementById('result').innerHTML = result;
        }

        async function callPythonWithArgs() {
            const result = await add(40, 2);
            document.getElementById('result').innerHTML = `Result: ${result}`;
        }

        function updateFromPython(message) {
            document.getElementById('result').innerHTML = `Python says: ${message}`;
        }
    </script>
</head>
<body>
    <h1>Python-JavaScript Binding Demo</h1>
    <button onclick="callPython()">Call Python</button>
    <button onclick="callPythonWithArgs()">Call Python with Args</button>
    <div id="result"></div>
</body>
</html>
"""

webview.navigate(f"data:text/html,{quote(html)}")
webview.run()
```

## Features

- Create desktop applications using HTML, CSS, and JavaScript
- Load local HTML files or remote URLs
- Bidirectional Python-JavaScript communication
- Window size and title customization
- Debug mode for development
- Cross-platform support (Windows, macOS, Linux)

## Development

### Setup Development Environment

```bash
# Install Python build tools
pip install --upgrade pip build twine

# Install GitHub CLI (choose one based on your OS):
# macOS
brew install gh

# Windows
winget install GitHub.cli
# or
choco install gh

# Linux (Debian/Ubuntu)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh
```

### Running Tests

```bash
python -m unittest discover tests
```

### Project Structure

```
webview_python/
├── src/
│   ├── webview.py      # Main webview implementation
│   └── ffi.py          # Foreign Function Interface
├── examples/           # Example applications
├── tests/             # Unit tests
└── README.md          # Documentation
```

### Release Process

For maintainers who want to release a new version:
1. **Test**
```bash
# Install dependencies if not installed 
pip install -r requirements.txt

# Run tests
pytest

# Build wheels
python -m build -n -w
```

2. **Update Version**
   ```bash
   # Ensure you have the latest code
   git pull origin main
   
   # Update version in pyproject.toml
   # Edit version = "x.y.z" to new version number
   ```

3. **Create Release**
   ```bash
   # Commit changes
   old_version=0.99.0
   new_version=0.99.1
   git add pyproject.toml
   git commit -m "Bump version to ${new_version}"
   git push origin main

   # Create and push tag
   git tag v${new_version}
   git push origin v${new_version}

   # Create GitHub release
    gh release create v${new_version} --title "${new_version}" \
        --notes "Full Changelog: https://github.com/congzhangzh/webview_python/compare/v${old_version}...v${new_version}"
   ```

4. **Monitor Release**
   - Check GitHub Actions progress in the Actions tab
   - Verify package on PyPI after workflow completion

### First-time Release Setup

1. **PyPI Setup**
   - Create account: https://pypi.org/account/register/
   - Generate API token: https://pypi.org/manage/account/token/

2. **GitHub Setup**
   - Repository Settings → Secrets and variables → Actions
   - Add new secret: `PYPI_API_TOKEN` with PyPI token value

## Roadmap

- [x] Publish to PyPI
- [x] Setup GitHub Actions for CI/CD
- [ ] Add preact example
- [ ] Add three.js example
- [ ] Add three.js fiber example
- [ ] Add screen saver 4 window example
- [ ] Add MRI principle demo example by three.js fiber
- [ ] Add screen saver 4 windows with MRI principle demo example by three.js fiber

## References

- [Webview](https://github.com/webview/webview)
- [webview_deno](https://github.com/eliassjogreen/webview_deno)

# License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "webview-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "webview, gui, desktop, application, html, web",
    "author": null,
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# Webview Python\n\n[![Test - Windows](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml/badge.svg?branch=main&event=push&label=Windows)](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml)\n[![Test - Linux](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml/badge.svg?branch=main&event=push&label=Linux)](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml)\n[![Test - macOS](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml/badge.svg?branch=main&event=push&label=macOS)](https://github.com/congzhangzh/webview_python/actions/workflows/test.yml)\n[![PyPI version](https://badge.fury.io/py/webview_python.svg)](https://badge.fury.io/py/webview_python)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Python Version](https://img.shields.io/pypi/pyversions/webview_python.svg)](https://pypi.org/project/webview_python/)\n\nPython bindings for the webview library, allowing you to create desktop applications with web technologies.\n\n## Installation\n\n```bash\npip install webview_python\n```\n\n## Usage\n\n### Display Inline HTML:\n\n```python\nfrom webview.webview import Webview\nfrom urllib.parse import quote\n\nhtml = \"\"\"\n<html>\n<body>\n<h1>Hello from Python Webview!</h1>\n</body>\n</html>\n\"\"\"\nwebview = Webview()\nwebview.navigate(f\"data:text/html,{quote(html)}\")\nwebview.run()\n```\n\n### Load Local HTML File:\n\n```python\nfrom webview.webview import Webview\nimport os\n\nwebview = Webview()\ncurrent_dir = os.path.dirname(os.path.abspath(__file__))\nhtml_path = os.path.join(current_dir, 'local.html')\nwebview.navigate(f\"file://{html_path}\")\nwebview.run()\n```\n\n### Load Remote URL:\n\n```python\nfrom webview.webview import Webview\nwebview = Webview()\nwebview.navigate(\"https://www.python.org\")\nwebview.run()\n```\n\n### Python-JavaScript Bindings:\n\n```python\nfrom webview.webview import Webview, Size, SizeHint\nfrom urllib.parse import quote\n\nwebview = Webview(debug=True)\n\n# Python functions that can be called from JavaScript\ndef hello():\n    webview.eval(\"updateFromPython('Hello from Python!')\")\n    return \"Hello from Python!\"\n\ndef add(a, b):\n    return a + b\n\n# Bind Python functions\nwebview.bind(\"hello\", hello)\nwebview.bind(\"add\", add)\n\n# Configure window\nwebview.title = \"Python-JavaScript Binding Demo\"\nwebview.size = Size(640, 480, SizeHint.FIXED)\n\n# Load HTML with JavaScript\nhtml = \"\"\"\n<html>\n<head>\n    <title>Python-JavaScript Binding Demo</title>\n    <script>\n        async function callPython() {\n            const result = await hello();\n            document.getElementById('result').innerHTML = result;\n        }\n\n        async function callPythonWithArgs() {\n            const result = await add(40, 2);\n            document.getElementById('result').innerHTML = `Result: ${result}`;\n        }\n\n        function updateFromPython(message) {\n            document.getElementById('result').innerHTML = `Python says: ${message}`;\n        }\n    </script>\n</head>\n<body>\n    <h1>Python-JavaScript Binding Demo</h1>\n    <button onclick=\"callPython()\">Call Python</button>\n    <button onclick=\"callPythonWithArgs()\">Call Python with Args</button>\n    <div id=\"result\"></div>\n</body>\n</html>\n\"\"\"\n\nwebview.navigate(f\"data:text/html,{quote(html)}\")\nwebview.run()\n```\n\n## Features\n\n- Create desktop applications using HTML, CSS, and JavaScript\n- Load local HTML files or remote URLs\n- Bidirectional Python-JavaScript communication\n- Window size and title customization\n- Debug mode for development\n- Cross-platform support (Windows, macOS, Linux)\n\n## Development\n\n### Setup Development Environment\n\n```bash\n# Install Python build tools\npip install --upgrade pip build twine\n\n# Install GitHub CLI (choose one based on your OS):\n# macOS\nbrew install gh\n\n# Windows\nwinget install GitHub.cli\n# or\nchoco install gh\n\n# Linux (Debian/Ubuntu)\ncurl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \\\n&& echo \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main\" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \\\n&& sudo apt update \\\n&& sudo apt install gh\n```\n\n### Running Tests\n\n```bash\npython -m unittest discover tests\n```\n\n### Project Structure\n\n```\nwebview_python/\n\u251c\u2500\u2500 src/\n\u2502   \u251c\u2500\u2500 webview.py      # Main webview implementation\n\u2502   \u2514\u2500\u2500 ffi.py          # Foreign Function Interface\n\u251c\u2500\u2500 examples/           # Example applications\n\u251c\u2500\u2500 tests/             # Unit tests\n\u2514\u2500\u2500 README.md          # Documentation\n```\n\n### Release Process\n\nFor maintainers who want to release a new version:\n1. **Test**\n```bash\n# Install dependencies if not installed \npip install -r requirements.txt\n\n# Run tests\npytest\n\n# Build wheels\npython -m build -n -w\n```\n\n2. **Update Version**\n   ```bash\n   # Ensure you have the latest code\n   git pull origin main\n   \n   # Update version in pyproject.toml\n   # Edit version = \"x.y.z\" to new version number\n   ```\n\n3. **Create Release**\n   ```bash\n   # Commit changes\n   old_version=0.99.0\n   new_version=0.99.1\n   git add pyproject.toml\n   git commit -m \"Bump version to ${new_version}\"\n   git push origin main\n\n   # Create and push tag\n   git tag v${new_version}\n   git push origin v${new_version}\n\n   # Create GitHub release\n    gh release create v${new_version} --title \"${new_version}\" \\\n        --notes \"Full Changelog: https://github.com/congzhangzh/webview_python/compare/v${old_version}...v${new_version}\"\n   ```\n\n4. **Monitor Release**\n   - Check GitHub Actions progress in the Actions tab\n   - Verify package on PyPI after workflow completion\n\n### First-time Release Setup\n\n1. **PyPI Setup**\n   - Create account: https://pypi.org/account/register/\n   - Generate API token: https://pypi.org/manage/account/token/\n\n2. **GitHub Setup**\n   - Repository Settings \u2192 Secrets and variables \u2192 Actions\n   - Add new secret: `PYPI_API_TOKEN` with PyPI token value\n\n## Roadmap\n\n- [x] Publish to PyPI\n- [x] Setup GitHub Actions for CI/CD\n- [ ] Add preact example\n- [ ] Add three.js example\n- [ ] Add three.js fiber example\n- [ ] Add screen saver 4 window example\n- [ ] Add MRI principle demo example by three.js fiber\n- [ ] Add screen saver 4 windows with MRI principle demo example by three.js fiber\n\n## References\n\n- [Webview](https://github.com/webview/webview)\n- [webview_deno](https://github.com/eliassjogreen/webview_deno)\n\n# License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Python Webview Contributors  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python bindings for the webview library, which completely follow deno_webview design and principles",
    "version": "0.99.16",
    "project_urls": {
        "Bug Tracker": "https://github.com/congzhangzh/webview_python/issues",
        "Homepage": "https://github.com/congzhangzh/webview_python",
        "Repository": "https://github.com/congzhangzh/webview_python.git"
    },
    "split_keywords": [
        "webview",
        " gui",
        " desktop",
        " application",
        " html",
        " web"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3fa602b62634ad2c1c1186f0a4a24598f058506b7b88402fb6843e5c67318e5d",
                "md5": "d1050a4030e1fd9ae90d2985e258b82f",
                "sha256": "2e5e4506ac0bc13432859e24cf63a22c5342825426998eb0b0b9403c09296016"
            },
            "downloads": -1,
            "filename": "webview_python-0.99.16-cp312-cp312-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "d1050a4030e1fd9ae90d2985e258b82f",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 41541,
            "upload_time": "2024-11-03T16:22:46",
            "upload_time_iso_8601": "2024-11-03T16:22:46.078121Z",
            "url": "https://files.pythonhosted.org/packages/3f/a6/02b62634ad2c1c1186f0a4a24598f058506b7b88402fb6843e5c67318e5d/webview_python-0.99.16-cp312-cp312-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5858ab87f1489c7f323de55356c0c9f788a03472c1249a5f12e114e0e7755d29",
                "md5": "b5f5f346f73027aa91c61e7069cd81b1",
                "sha256": "c8b573d072316f37e70ca8fec0cdd3e042bbb8b6ebb1a4968704ca197bcdfed1"
            },
            "downloads": -1,
            "filename": "webview_python-0.99.16-cp312-cp312-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "b5f5f346f73027aa91c61e7069cd81b1",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 42032,
            "upload_time": "2024-11-03T16:22:47",
            "upload_time_iso_8601": "2024-11-03T16:22:47.622063Z",
            "url": "https://files.pythonhosted.org/packages/58/58/ab87f1489c7f323de55356c0c9f788a03472c1249a5f12e114e0e7755d29/webview_python-0.99.16-cp312-cp312-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76ce90d9d179e8a620c0f6789239dacb654f32a6160a7cabc4ab70a8ca015287",
                "md5": "e7c59f4d6fe000e754c230a8b1d2f8e3",
                "sha256": "00b79b7f1cbee8828b4fb64242969a728029c789c3389ae7188a174457250b35"
            },
            "downloads": -1,
            "filename": "webview_python-0.99.16-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "e7c59f4d6fe000e754c230a8b1d2f8e3",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 63137,
            "upload_time": "2024-11-03T16:22:49",
            "upload_time_iso_8601": "2024-11-03T16:22:49.104601Z",
            "url": "https://files.pythonhosted.org/packages/76/ce/90d9d179e8a620c0f6789239dacb654f32a6160a7cabc4ab70a8ca015287/webview_python-0.99.16-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "39e37d20dafce475032c1b89ecc77235924966cbfd844d6096efccd85b07fb7f",
                "md5": "7bea0e1af64ca2b6fea952a4686b0b37",
                "sha256": "f947f2dafd6bb77fa268329af04c4f4f35b3760c35666170f9c848fe4eb24c6b"
            },
            "downloads": -1,
            "filename": "webview_python-0.99.16-cp312-cp312-musllinux_1_1_x86_64.whl",
            "has_sig": false,
            "md5_digest": "7bea0e1af64ca2b6fea952a4686b0b37",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 66442,
            "upload_time": "2024-11-03T16:22:50",
            "upload_time_iso_8601": "2024-11-03T16:22:50.370317Z",
            "url": "https://files.pythonhosted.org/packages/39/e3/7d20dafce475032c1b89ecc77235924966cbfd844d6096efccd85b07fb7f/webview_python-0.99.16-cp312-cp312-musllinux_1_1_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "107ee862d1657f9a77e1b718aabc715ff84a67a259421a19996327017cdbab8c",
                "md5": "9c625ac2022ae167f576a041efc026ca",
                "sha256": "44f225d4465eaf35a213f66caab94a892f6d83e186d265389fb2009d5eef64af"
            },
            "downloads": -1,
            "filename": "webview_python-0.99.16-cp312-cp312-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "9c625ac2022ae167f576a041efc026ca",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.8",
            "size": 44732,
            "upload_time": "2024-11-03T16:22:51",
            "upload_time_iso_8601": "2024-11-03T16:22:51.613838Z",
            "url": "https://files.pythonhosted.org/packages/10/7e/e862d1657f9a77e1b718aabc715ff84a67a259421a19996327017cdbab8c/webview_python-0.99.16-cp312-cp312-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-03 16:22:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "congzhangzh",
    "github_project": "webview_python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "webview-python"
}
        
Elapsed time: 0.62934s