pywry


Namepywry JSON
Version 0.6.2 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2023-10-19 04:47:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyWry Web Viewer

![PyWryLogo](https://raw.githubusercontent.com/OpenBB-finance/pywry/main/assets/PyWry.png)

Easily create HTML webviewers in python utilizing the [wry](https://github.com/tauri-apps/wry) library. Unlike many HTML viewers that exist for Python - Pywry allows you to run javacsript. PyWry is also a ~2mb footprint for Mac and Windows - Linux will require a few more libraries which are listed below.

Please note: this library is currently in early alpha and is NOT ready for production use.

## Installation

---------------------
PyWry is available on PyPI and can be installed with pip:

```bash
pip install pywry
```

---------------------
For development, you can install from source with the following steps:

- Clone the repository: `git clone https://github.com/OpenBB-finance/pywry.git`
- Install rust: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
- Create a virtual environment: `python -m venv venv`
- Acitvate the environment: `source venv/bin/activate` (Unix) or `venv\Scripts\activate` (Windows)
- Install dependencies: `pip install .[dev]`
- Build the pip package: `maturin build`
- Install the package: `pip install [file path from above] --force-reinstall`

## Usage

```python
import asyncio
import sys

from pywry import PyWry


async def main_loop():
    while True:
        await asyncio.sleep(1)


if __name__ == "__main__":
    try:
        handler = PyWry()
        handler.send_html("<h1 style='color: red;'>Welcome to PyWry!</h1>")
        handler.start()

        # PyWry creates a new thread for the backend,
        # so we need to run the main loop in the main thread.
        # otherwise, the program will exit immediately.
        handler.loop.run_until_complete(main_loop())
    except KeyboardInterrupt:
        print("Keyboard interrupt detected. Exiting...")
        sys.exit(0)
```

## JSON Keys

PyWry uses a JSON object to communicate between the python and rust backends and the javascript
frontend. The following keys are available:

| Key | Type | Description |
| --- | --- | --- |
| `html` | `Path \| str` | The path to the HTML file to be loaded, or HTML string. |
| `title` | `str` | The title of the window. |
| `icon` | `str \| Path` | The path to `png` icon to be used for the window. |
| `json_data` | `str \| dict` | A JSON string or dictionary to be passed to the javascript frontend. (see below) |
| `height` | `int` | The height of the window. |
| `width` | `int` | The width of the window. |
| `download_path` | `str \| Path` | The path to the download directory. |

## Javascript

PyWry allows you to run javascript in the frontend. To do this, you can pass a dictionary
of data to the `json_data` key in the `send_html` method. This dictionary will be converted
to a JSON string and passed to the frontend. You can then access this data in the frontend
by using the `window.json_data` object. For example:

---------------------

### Python

```python
from pathlib import Path
# code from above ...

# change send_html line to:
        handler.send_html(
            html=Path(__file__).parent / "index.html", json_data={"name": "PyWry"}
        )
```

---------------------

### HTML

```html
<html>
    <head>
        <script>
            window.onload = () => {
                // if you passed a JSON string, you will need to parse it first
                if (typeof window.json_data === "string") {
                    window.json_data = JSON.parse(window.json_data);
                }
                document.getElementById("name").innerHTML = window.json_data.name;
            };
        </script>
    </head>
    <body>
        <h1 style='color: red;'>Hello, <span id="name"></span>!</h1>
    </body>
</html>
```

---------------------

## Platform-specific notes

All platforms use [TAO](https://github.com/tauri-apps/tao) to build the window, and wry re-exports it as an application module. Here is the underlying web engine each platform uses, and some dependencies you might need to install.

### Linux

Tao uses [gtk-rs](https://gtk-rs.org/) and its related libraries for window creation and wry also needs [WebKitGTK](https://webkitgtk.org/) for WebView. So please make sure the following packages are installed:

#### Arch Linux / Manjaro

```bash
sudo pacman -S webkit2gtk
```

#### Debian / Ubuntu

```bash
sudo apt install libwebkit2gtk-4.0-dev
```

#### Fedora / CentOS / AlmaLinux

```bash
sudo dnf install gtk3-devel webkit2gtk3-devel
```

### macOS

WebKit is native to macOS, so no additional dependencies are needed.

### Windows

WebView2 provided by Microsoft Edge Chromium is used. So wry supports Windows 7, 8, 10 and 11.

---------------------

### Troubleshooting Linux

#### `"/lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined symbol: g_module_open_full"`

This is a known issue with the `gio` library. You can fix it by installing the `libglib2.0-dev` package.



PyWry is a project that aims to provide Python bindings for WRY, a cross-platform webview library. WRY is a trademark of the Tauri Program within the Commons Conservancy and PyWry is not officially endorsed or supported by them. PyWry is an independent and community-driven effort that respects the original goals and values of Tauri and WRY. PyWry does not claim any ownership or affiliation with WRY or the Tauri Program.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pywry",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/60/df/2bd468f465011fb021f45cbe5cc9f1cfe15872c61e1cab2a7962bd4f4860/pywry-0.6.2.tar.gz",
    "platform": null,
    "description": "# PyWry Web Viewer\n\n![PyWryLogo](https://raw.githubusercontent.com/OpenBB-finance/pywry/main/assets/PyWry.png)\n\nEasily create HTML webviewers in python utilizing the [wry](https://github.com/tauri-apps/wry) library. Unlike many HTML viewers that exist for Python - Pywry allows you to run javacsript. PyWry is also a ~2mb footprint for Mac and Windows - Linux will require a few more libraries which are listed below.\n\nPlease note: this library is currently in early alpha and is NOT ready for production use.\n\n## Installation\n\n---------------------\nPyWry is available on PyPI and can be installed with pip:\n\n```bash\npip install pywry\n```\n\n---------------------\nFor development, you can install from source with the following steps:\n\n- Clone the repository: `git clone https://github.com/OpenBB-finance/pywry.git`\n- Install rust: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`\n- Create a virtual environment: `python -m venv venv`\n- Acitvate the environment: `source venv/bin/activate` (Unix) or `venv\\Scripts\\activate` (Windows)\n- Install dependencies: `pip install .[dev]`\n- Build the pip package: `maturin build`\n- Install the package: `pip install [file path from above] --force-reinstall`\n\n## Usage\n\n```python\nimport asyncio\nimport sys\n\nfrom pywry import PyWry\n\n\nasync def main_loop():\n    while True:\n        await asyncio.sleep(1)\n\n\nif __name__ == \"__main__\":\n    try:\n        handler = PyWry()\n        handler.send_html(\"<h1 style='color: red;'>Welcome to PyWry!</h1>\")\n        handler.start()\n\n        # PyWry creates a new thread for the backend,\n        # so we need to run the main loop in the main thread.\n        # otherwise, the program will exit immediately.\n        handler.loop.run_until_complete(main_loop())\n    except KeyboardInterrupt:\n        print(\"Keyboard interrupt detected. Exiting...\")\n        sys.exit(0)\n```\n\n## JSON Keys\n\nPyWry uses a JSON object to communicate between the python and rust backends and the javascript\nfrontend. The following keys are available:\n\n| Key | Type | Description |\n| --- | --- | --- |\n| `html` | `Path \\| str` | The path to the HTML file to be loaded, or HTML string. |\n| `title` | `str` | The title of the window. |\n| `icon` | `str \\| Path` | The path to `png` icon to be used for the window. |\n| `json_data` | `str \\| dict` | A JSON string or dictionary to be passed to the javascript frontend. (see below) |\n| `height` | `int` | The height of the window. |\n| `width` | `int` | The width of the window. |\n| `download_path` | `str \\| Path` | The path to the download directory. |\n\n## Javascript\n\nPyWry allows you to run javascript in the frontend. To do this, you can pass a dictionary\nof data to the `json_data` key in the `send_html` method. This dictionary will be converted\nto a JSON string and passed to the frontend. You can then access this data in the frontend\nby using the `window.json_data` object. For example:\n\n---------------------\n\n### Python\n\n```python\nfrom pathlib import Path\n# code from above ...\n\n# change send_html line to:\n        handler.send_html(\n            html=Path(__file__).parent / \"index.html\", json_data={\"name\": \"PyWry\"}\n        )\n```\n\n---------------------\n\n### HTML\n\n```html\n<html>\n    <head>\n        <script>\n            window.onload = () => {\n                // if you passed a JSON string, you will need to parse it first\n                if (typeof window.json_data === \"string\") {\n                    window.json_data = JSON.parse(window.json_data);\n                }\n                document.getElementById(\"name\").innerHTML = window.json_data.name;\n            };\n        </script>\n    </head>\n    <body>\n        <h1 style='color: red;'>Hello, <span id=\"name\"></span>!</h1>\n    </body>\n</html>\n```\n\n---------------------\n\n## Platform-specific notes\n\nAll platforms use [TAO](https://github.com/tauri-apps/tao) to build the window, and wry re-exports it as an application module. Here is the underlying web engine each platform uses, and some dependencies you might need to install.\n\n### Linux\n\nTao uses [gtk-rs](https://gtk-rs.org/) and its related libraries for window creation and wry also needs [WebKitGTK](https://webkitgtk.org/) for WebView. So please make sure the following packages are installed:\n\n#### Arch Linux / Manjaro\n\n```bash\nsudo pacman -S webkit2gtk\n```\n\n#### Debian / Ubuntu\n\n```bash\nsudo apt install libwebkit2gtk-4.0-dev\n```\n\n#### Fedora / CentOS / AlmaLinux\n\n```bash\nsudo dnf install gtk3-devel webkit2gtk3-devel\n```\n\n### macOS\n\nWebKit is native to macOS, so no additional dependencies are needed.\n\n### Windows\n\nWebView2 provided by Microsoft Edge Chromium is used. So wry supports Windows 7, 8, 10 and 11.\n\n---------------------\n\n### Troubleshooting Linux\n\n#### `\"/lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined symbol: g_module_open_full\"`\n\nThis is a known issue with the `gio` library. You can fix it by installing the `libglib2.0-dev` package.\n\n\n\nPyWry is a project that aims to provide Python bindings for WRY, a cross-platform webview library. WRY is a trademark of the Tauri Program within the Commons Conservancy and PyWry is not officially endorsed or supported by them. PyWry is an independent and community-driven effort that respects the original goals and values of Tauri and WRY. PyWry does not claim any ownership or affiliation with WRY or the Tauri Program.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "0.6.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fa0e0a4b6436433678d49790683ea869e40cca6ecc36f6abdaf01a489298a8f8",
                "md5": "c9892b071d8dfc9b46adc6a25a273f8f",
                "sha256": "45d6bb827bf76b2532a9d70b539209d70f37dfb13e9862549b7bff8500ad2495"
            },
            "downloads": -1,
            "filename": "pywry-0.6.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl",
            "has_sig": false,
            "md5_digest": "c9892b071d8dfc9b46adc6a25a273f8f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 2303900,
            "upload_time": "2023-10-19T04:47:46",
            "upload_time_iso_8601": "2023-10-19T04:47:46.882199Z",
            "url": "https://files.pythonhosted.org/packages/fa/0e/0a4b6436433678d49790683ea869e40cca6ecc36f6abdaf01a489298a8f8/pywry-0.6.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "02cc00c1c93ff5df28cb95a1838f2405f7943e1c0c1a965a6a14670ca3ea9745",
                "md5": "e95004e6fe60ba8af9886b948cd562eb",
                "sha256": "1d9ffd826a3a08c132843340e6d896efb7b972b301d045e3239a7dc08d9cac2f"
            },
            "downloads": -1,
            "filename": "pywry-0.6.2-py3-none-manylinux_2_28_x86_64.whl",
            "has_sig": false,
            "md5_digest": "e95004e6fe60ba8af9886b948cd562eb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 66838493,
            "upload_time": "2023-10-19T04:47:50",
            "upload_time_iso_8601": "2023-10-19T04:47:50.226620Z",
            "url": "https://files.pythonhosted.org/packages/02/cc/00c1c93ff5df28cb95a1838f2405f7943e1c0c1a965a6a14670ca3ea9745/pywry-0.6.2-py3-none-manylinux_2_28_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1909d33a4fedf333af8cb208bb9b9a974fbd025c654c6b231b77e22766591ed1",
                "md5": "3251464c3f230db8f19d723fc0466f78",
                "sha256": "4f0e5b502555ee8b8e799baeaebe63243a84b7ce51df01a1c439dbc4e8227b9e"
            },
            "downloads": -1,
            "filename": "pywry-0.6.2-py3-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "3251464c3f230db8f19d723fc0466f78",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 868356,
            "upload_time": "2023-10-19T04:47:53",
            "upload_time_iso_8601": "2023-10-19T04:47:53.582301Z",
            "url": "https://files.pythonhosted.org/packages/19/09/d33a4fedf333af8cb208bb9b9a974fbd025c654c6b231b77e22766591ed1/pywry-0.6.2-py3-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "60df2bd468f465011fb021f45cbe5cc9f1cfe15872c61e1cab2a7962bd4f4860",
                "md5": "4ce42f4695e4691432052fd0999d7afc",
                "sha256": "9bd88c36ab0860728d9e64360010f8abcede43645656030e4a63e69e81a98c95"
            },
            "downloads": -1,
            "filename": "pywry-0.6.2.tar.gz",
            "has_sig": false,
            "md5_digest": "4ce42f4695e4691432052fd0999d7afc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 38983,
            "upload_time": "2023-10-19T04:47:55",
            "upload_time_iso_8601": "2023-10-19T04:47:55.225747Z",
            "url": "https://files.pythonhosted.org/packages/60/df/2bd468f465011fb021f45cbe5cc9f1cfe15872c61e1cab2a7962bd4f4860/pywry-0.6.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-19 04:47:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pywry"
}
        
Elapsed time: 0.12428s