Skip to main content

Use your web dev skills to design UIs for your Python apps with this simple, Rust-powered webview library.

Project description

Dry: a simple webview library

Dry is a tiny, no-dependency webview library that lets you use your web development skills to create user interfaces for your Python applications. Built with Rust on top of Wry.

Why?

  • Familiar Tech: Use HTML, CSS and JS to design your UIs!
  • Flexible Content: Render from an HTML string or from a URL.
  • Customizable: Support for borderless windows with custom titlebars!
  • Callbacks: Interact with Python from JavaScript!

Installation

Getting started with Dry is straightforward. Simply use pip or uv to install:

pip install dry-webview
uv add dry-webview

Getting Started

Here's a quick example of how to use Dry to create a simple webview:

from dry import Webview

wv = Webview()
wv.title = "My Python App!"
wv.content = "<h1>Hello, World!</h1>"
wv.run()

For more examples, check out the examples directory.

Features

Flexible Content

The Webview class supports loading content from a string containing HTML or from a URL. You could, for example, compile your HTML, CSS and JS into a single file and load it into the webview.

wv.content = "<h1>Hello, World!</h1>" or "http://localhost:8000"

If your UI needs to come from a server, know that wv.run() blocks the main thread. Consider running the server from a separate thread (preferably a daemon one, which will shutdown along with the main thread).

import threading
from dry import Webview

def serve_files():
    # Your server logic here

if __name__ == "__main__":

    thread = threading.Thread(target=serve_files, daemon=True)
    thread.start()

    wv = Webview()
    wv.content = "http://localhost:8000"
    wv.run()

Custom Titlebar

Dry supports custom titlebars, allowing you to create a unique look for your application. You tell the Webview class to hide decorations like this:

wv.decorations = False

And then you can use data-drag-region to define the draggable area in your HTML, which will probably be your custom titlebar:

<div data-drag-region>
    <h1>Custom Titlebar</h1>
</div>

A window without decorations will automatically be draggable within the data-drag-region area, having resize handles automatically positioned at all corners.

With or without decorations, basic window controls are available from the DOM, allowing you to minimize, maximize and close window. More are to come in the future.

<button onclick="window.minimize()">Minimize</button>
<button onclick="window.toggleMaximize()">Maximize</button>
<button onclick="window.close()">Close</button>

Callbacks

You can use callbacks to interact with Python from JavaScript. You define them like this:

def hello_world():
    return "Hello, World!"

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

api = {
    "helloWorld": hello_world,
    "dumbSum": dumb_sum
}

wv = Webview()
wv.api = api
wv.run()

And then you can call them from JavaScript as follows:

const hello = await window.api.helloWorld();
const sum = await window.api.dumbSum(1, 2);

console.log(hello); // Hello, World!
console.log(sum); // 3

Be aware of the supported data types for function arguments and return values:

Python Type JavaScript Type
None null
bool boolean
int number
float number
str string
list array
tuple array
set array
dict object
bytes number[]

Other

The Webview class has a few options you can set through its properties:

Property Description
title The window title. Defaults to 'My Dry Webview'.
min_size Minimum window dimensions (width, height).
size Initial window dimensions (width, height).
decorations Whether to show window decorations (title bar, borders).
icon_path Path to the window icon file (.ico format).
content HTML content or URL to display in the window.
api JavaScript-accessible Python functions.
dev_tools Whether to enable developer tools.
user_data_folder Path to store user data. Defaults to temp folder.

Current Status

Dry is in its early stages and currently supports Windows only. Expect ongoing development, new features, and potential changes.

Platform Compatibility

Platform Status
Windows 11 ✅ Tested
Linux ❌ Not Yet
macOS ❌ Not Yet

Python Compatibility

Python Version Status
CPython 3.11 ✅ Tested
CPython 3.12 ✅ Tested
CPython 3.13 ❌ Not Yet

License

Dry is distributed under the MIT License. For more details, see the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dry_webview-0.3.0.tar.gz (48.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dry_webview-0.3.0-cp313-cp313-win_amd64.whl (392.3 kB view details)

Uploaded CPython 3.13Windows x86-64

dry_webview-0.3.0-cp312-cp312-win_amd64.whl (392.5 kB view details)

Uploaded CPython 3.12Windows x86-64

dry_webview-0.3.0-cp311-cp311-win_amd64.whl (393.4 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file dry_webview-0.3.0.tar.gz.

File metadata

  • Download URL: dry_webview-0.3.0.tar.gz
  • Upload date:
  • Size: 48.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.8

File hashes

Hashes for dry_webview-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a99665c20f4ac503566fffc647c44fa96fb5ad2cc9f3eca4d6f3c3479b243e67
MD5 335aab7286a7c4bd0c666b7d3c1836c9
BLAKE2b-256 437860f39b3306055909445219420a3cc6df36e9ccd32066290042c03243aa7f

See more details on using hashes here.

File details

Details for the file dry_webview-0.3.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for dry_webview-0.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a23321ff826178f0af847e267faf5ab574df5f663009b5ad415bbb1920216877
MD5 2f02eb898f0bf5aaec3fb72d92fc219c
BLAKE2b-256 fd8e03bc77c380abb20c23de864642e2e890b97855c372b6940c7d8a815cb253

See more details on using hashes here.

File details

Details for the file dry_webview-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for dry_webview-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8ec6dd2dc17c34d1bb1fb00f8022172726f99c5dae97cb89175c017b4dccfa33
MD5 d15ad7d5f3ca924b6e8b741f51f99736
BLAKE2b-256 402b6bafffec38bd01b22613b990ddfea3c2ec0c2fbe068ec17850b6be926bbb

See more details on using hashes here.

File details

Details for the file dry_webview-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for dry_webview-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cc7fc953741b807892c4b4ecca98e2d468f090e308d0498a77d61ff43b731fc7
MD5 f656104509948cb3eb3adc13d3005a7e
BLAKE2b-256 3c5e6fbff8913dbf9d9dbb3caef7f91f82cad8b19163bb301fd5adff2a081809

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page