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 ✅ Tested

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.1.tar.gz (48.4 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.1-cp313-cp313-win_amd64.whl (392.3 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

dry_webview-0.3.1-cp311-cp311-win_amd64.whl (393.3 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

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

File metadata

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

File hashes

Hashes for dry_webview-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3e1b169e17f01de6f952f9968d804103daa5d1ed9d3275d1b090c5b6d3461bf4
MD5 eaa8e1a80edad5d2d9947144ba802461
BLAKE2b-256 d5fc2a1ee23be44380b89c118c3affbbd3ea186668c082e551a2129ccf23f515

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dry_webview-0.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fe8cedb1d73653d451a4ef811a0b3bd04e93727ab420690c49f4fd015524f8d8
MD5 ca5834f475fc74a571a47fdcd18aed99
BLAKE2b-256 0bc8015f33264de3f5b3dfc86c64324ca0dad8ba26cc03d9952424199c8eb155

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dry_webview-0.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 556978d1ab5f89858dea3d03dd01ad57413bea02629ca6462e0ae6ec03710995
MD5 f4d056a863ad7781c1ff92a63affa333
BLAKE2b-256 f8c37b6ab46119dbf544cefbb0439cf971b2beb9be971c3c22a8fa0f258d4e88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dry_webview-0.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0a3bcbb110a6ca8d9f980bbcba4b7fb9c1996f15bad7d8bb712f1c5f402e28a8
MD5 5e475cdb85ffe4abd59febe058dd4222
BLAKE2b-256 0610556a314997fd9ebac7d88f5fe0fe2e78a31969a3286da5c39f885b57eea0

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