Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyWry Web Viewer

PyWryLogo

Easily create HTML webviewers in python utilizing the 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:

pip install pywry-nightly

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

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

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>
    <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 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 and its related libraries for window creation and wry also needs WebKitGTK for WebView. So please make sure the following packages are installed:

Arch Linux / Manjaro

sudo pacman -S webkit2gtk

Debian / Ubuntu

sudo apt install libwebkit2gtk-4.0-dev

Fedora / CentOS / AlmaLinux

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.

Metadata

Release files for pywry-nightly 0.6.1.dev20230917

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pywry-nightly 0.6.1.dev20230917
File Size Uploaded
pywry_nightly-0.6.1.dev20230917.tar.gz 71.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pywry-nightly 0.6.1.dev20230917
File Interpreter ABI Platform
pywry_nightly-0.6.1.dev20230917-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pywry_nightly-0.6.1.dev20230917-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details
pywry_nightly-0.6.1.dev20230917-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl Python 3 none macOS 10.9+ x86-64, macOS 11.0+ ARM64, macOS 10.9+ universal2 (ARM64, x86-64) Details

Total release size: 69.2 MB

Release files / pywry_nightly-0.6.1.dev20230917.tar.gz

Download URL pywry_nightly-0.6.1.dev20230917.tar.gz
Size 71.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cdd75268ebc781934871e0c78cfcea0b892499ab315d7fd61c960fa0f8bc2026
BLAKE2b-256 checksum
How to use checksums
917895b577b4c22fe02e8720562a28359b9a262dc8580153ac7a2bffc74159d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.2.3

Release files / pywry_nightly-0.6.1.dev20230917-py3-none-win_amd64.whl

Download URL pywry_nightly-0.6.1.dev20230917-py3-none-win_amd64.whl
Size 882.5 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
e84d9777efcff49b26b8e7a83ac68365bb08b31f3d4e5b41387b05142dd9e7dd
BLAKE2b-256 checksum
How to use checksums
d76749c1ea33338b6c4a81cfb48c1ed6066aff3852706b027dba784b263cb1cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.2.3

Release files / pywry_nightly-0.6.1.dev20230917-py3-none-manylinux_2_28_x86_64.whl

Download URL pywry_nightly-0.6.1.dev20230917-py3-none-manylinux_2_28_x86_64.whl
Size 66.0 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
e42d68f16c0d8c97ffee30597e200fe07e860dd8d0fd2cf67cb4c763d7b9b278
BLAKE2b-256 checksum
How to use checksums
a84d7643be4ed068bab92c9bc00878ca47e51f0d6fdbc8e4b641cad71351a236
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.2.3

Release files / pywry_nightly-0.6.1.dev20230917-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl

Download URL pywry_nightly-0.6.1.dev20230917-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Size 2.3 MB
Tags Python 3 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
774aa90c412eac5af99f3274f3b28dead5279d1e5bcc1fbbc3ef76a321dd0b93
BLAKE2b-256 checksum
How to use checksums
81e0a30aab2fd3a42e3e6e9b802cf982294aa654d4772829bf0b476286fe50ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.2.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page