Name | dry-webview JSON |
Version |
0.3.2
JSON |
| download |
home_page | None |
Summary | Use your web dev skills to design UIs for your Python apps with this simple, Rust-powered webview library. |
upload_time | 2024-12-09 01:43:39 |
maintainer | None |
docs_url | None |
author | Otávio Barradas |
requires_python | >=3.11 |
license | MIT |
keywords |
webview
gui
rust
ui
web
python
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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](https://www.rust-lang.org/) on top of [Wry](https://github.com/tauri-apps/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:
```bash
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:
```python
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](https://github.com/barradasotavio/dry/tree/master/examples).
## 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.
```python
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).
```python
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:
```python
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:
```html
<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.
```html
<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:
```python
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:
```javascript
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](https://github.com/barradasotavio/dry/blob/master/LICENSE) file.
Raw data
{
"_id": null,
"home_page": null,
"name": "dry-webview",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "webview, gui, rust, ui, web, python",
"author": "Ot\u00e1vio Barradas",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/91/37/84420b68a3d000179ee820c3041d4a6077a061571ae727c47e84e6841835/dry_webview-0.3.2.tar.gz",
"platform": null,
"description": "# Dry: a simple webview library\r\n\r\n**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](https://www.rust-lang.org/) on top of [Wry](https://github.com/tauri-apps/wry).\r\n\r\n## Why?\r\n\r\n- **Familiar Tech**: Use HTML, CSS and JS to design your UIs!\r\n- **Flexible Content**: Render from an HTML string or from a URL.\r\n- **Customizable**: Support for borderless windows with custom titlebars!\r\n- **Callbacks**: Interact with Python from JavaScript!\r\n\r\n## Installation\r\n\r\nGetting started with Dry is straightforward. Simply use `pip` or `uv` to install:\r\n\r\n```bash\r\npip install dry-webview\r\nuv add dry-webview\r\n```\r\n\r\n## Getting Started\r\n\r\nHere's a quick example of how to use Dry to create a simple webview:\r\n\r\n```python\r\nfrom dry import Webview\r\n\r\nwv = Webview()\r\nwv.title = \"My Python App!\"\r\nwv.content = \"<h1>Hello, World!</h1>\"\r\nwv.run()\r\n```\r\n\r\nFor more examples, check out the [examples directory](https://github.com/barradasotavio/dry/tree/master/examples).\r\n\r\n\r\n## Features\r\n\r\n### Flexible Content\r\n\r\nThe `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.\r\n\r\n```python\r\nwv.content = \"<h1>Hello, World!</h1>\" or \"http://localhost:8000\"\r\n```\r\n\r\nIf 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).\r\n\r\n```python\r\nimport threading\r\nfrom dry import Webview\r\n\r\ndef serve_files():\r\n # Your server logic here\r\n\r\nif __name__ == \"__main__\":\r\n\r\n thread = threading.Thread(target=serve_files, daemon=True)\r\n thread.start()\r\n\r\n wv = Webview()\r\n wv.content = \"http://localhost:8000\"\r\n wv.run()\r\n```\r\n\r\n### Custom Titlebar\r\n\r\nDry supports custom titlebars, allowing you to create a unique look for your application. You tell the `Webview` class to hide decorations like this:\r\n\r\n```python\r\nwv.decorations = False\r\n```\r\n\r\nAnd then you can use `data-drag-region` to define the draggable area in your HTML, which will probably be your custom titlebar:\r\n\r\n```html\r\n<div data-drag-region>\r\n <h1>Custom Titlebar</h1>\r\n</div>\r\n```\r\n\r\nA window without decorations will automatically be draggable within the `data-drag-region` area, having resize handles automatically positioned at all corners.\r\n\r\nWith 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.\r\n\r\n```html\r\n<button onclick=\"window.minimize()\">Minimize</button>\r\n<button onclick=\"window.toggleMaximize()\">Maximize</button>\r\n<button onclick=\"window.close()\">Close</button>\r\n```\r\n\r\n### Callbacks\r\n\r\nYou can use callbacks to interact with Python from JavaScript. You define them like this:\r\n\r\n```python\r\ndef hello_world():\r\n return \"Hello, World!\"\r\n\r\ndef dumb_sum(a, b):\r\n return a + b\r\n\r\napi = {\r\n \"helloWorld\": hello_world,\r\n \"dumbSum\": dumb_sum\r\n}\r\n\r\nwv = Webview()\r\nwv.api = api\r\nwv.run()\r\n```\r\n\r\nAnd then you can call them from JavaScript as follows:\r\n\r\n```javascript\r\nconst hello = await window.api.helloWorld();\r\nconst sum = await window.api.dumbSum(1, 2);\r\n\r\nconsole.log(hello); // Hello, World!\r\nconsole.log(sum); // 3\r\n```\r\n\r\nBe aware of the supported data types for function arguments and return values:\r\n\r\n| Python Type | JavaScript Type |\r\n| ----------- | --------------- |\r\n| None | null |\r\n| bool | boolean |\r\n| int | number |\r\n| float | number |\r\n| str | string |\r\n| list | array |\r\n| tuple | array |\r\n| set | array |\r\n| dict | object |\r\n| bytes | number[] |\r\n\r\n### Other\r\n\r\nThe `Webview` class has a few options you can set through its properties:\r\n\r\n| Property | Description |\r\n| ---------------- | ---------------------------------------------------------------------------------------- |\r\n| title | The window title. Defaults to 'My Dry Webview'. |\r\n| min_size | Minimum window dimensions (width, height). |\r\n| size | Initial window dimensions (width, height). |\r\n| decorations | Whether to show window decorations (title bar, borders). |\r\n| icon_path | Path to the window icon file (.ico format). |\r\n| content | HTML content or URL to display in the window. |\r\n| api | JavaScript-accessible Python functions. |\r\n| dev_tools | Whether to enable developer tools. |\r\n| user_data_folder | Path to store user data. Defaults to temp folder. |\r\n\r\n\r\n## Current Status\r\n\r\nDry is in its early stages and currently supports Windows only. Expect ongoing development, new features, and potential changes.\r\n\r\n## Platform Compatibility\r\n\r\n| Platform | Status |\r\n| ---------- | --------- |\r\n| Windows 11 | \u2705 Tested |\r\n| Linux | \u274c Not Yet |\r\n| macOS | \u274c Not Yet |\r\n\r\n## Python Compatibility\r\n\r\n| Python Version | Status |\r\n| -------------- | --------- |\r\n| CPython 3.11 | \u2705 Tested |\r\n| CPython 3.12 | \u2705 Tested |\r\n| CPython 3.13 | \u2705 Tested |\r\n\r\n## License\r\n\r\nDry is distributed under the MIT License. For more details, see the [LICENSE](https://github.com/barradasotavio/dry/blob/master/LICENSE) file.\r\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Use your web dev skills to design UIs for your Python apps with this simple, Rust-powered webview library.",
"version": "0.3.2",
"project_urls": {
"Homepage": "https://github.com/barradasotavio/dry",
"Repository": "https://github.com/barradasotavio/dry.git"
},
"split_keywords": [
"webview",
" gui",
" rust",
" ui",
" web",
" python"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "3235cf4ff7b9cd8335894297769c757eaeb94003d67080f3aa9f20d9ec5749d0",
"md5": "611c07b0bce59b977e8893f60e8b7e7f",
"sha256": "2f94db13290e942d180b4af635a54dd1f9ac3d98595309b216bf83c2c38a5cee"
},
"downloads": -1,
"filename": "dry_webview-0.3.2-cp311-cp311-win_amd64.whl",
"has_sig": false,
"md5_digest": "611c07b0bce59b977e8893f60e8b7e7f",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.11",
"size": 393311,
"upload_time": "2024-12-09T01:43:37",
"upload_time_iso_8601": "2024-12-09T01:43:37.060518Z",
"url": "https://files.pythonhosted.org/packages/32/35/cf4ff7b9cd8335894297769c757eaeb94003d67080f3aa9f20d9ec5749d0/dry_webview-0.3.2-cp311-cp311-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "076ff10f3e416c238236c91184dcfb2f41c1301231589421b06a1915709930d1",
"md5": "0117dd965301363e0434143b53d78bf6",
"sha256": "dac8a1fcd622ad6fae185f80991b40dca8ad5e47cdbd5a4d8e0fe4314b33dcde"
},
"downloads": -1,
"filename": "dry_webview-0.3.2-cp312-cp312-win_amd64.whl",
"has_sig": false,
"md5_digest": "0117dd965301363e0434143b53d78bf6",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.11",
"size": 392522,
"upload_time": "2024-12-09T01:44:23",
"upload_time_iso_8601": "2024-12-09T01:44:23.470398Z",
"url": "https://files.pythonhosted.org/packages/07/6f/f10f3e416c238236c91184dcfb2f41c1301231589421b06a1915709930d1/dry_webview-0.3.2-cp312-cp312-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "5075b0f621f49ce439607d6e82656f295e8e0f670b961fb25b92d57840412c9a",
"md5": "e80427ac1f20646bd0b275df5ea2aa64",
"sha256": "d6bbb8caed74dc9ecff05fd91a03e41c8986f0844f4d7d06ab2a8292e88591a1"
},
"downloads": -1,
"filename": "dry_webview-0.3.2-cp313-cp313-win_amd64.whl",
"has_sig": false,
"md5_digest": "e80427ac1f20646bd0b275df5ea2aa64",
"packagetype": "bdist_wheel",
"python_version": "cp313",
"requires_python": ">=3.11",
"size": 392366,
"upload_time": "2024-12-09T01:45:08",
"upload_time_iso_8601": "2024-12-09T01:45:08.911652Z",
"url": "https://files.pythonhosted.org/packages/50/75/b0f621f49ce439607d6e82656f295e8e0f670b961fb25b92d57840412c9a/dry_webview-0.3.2-cp313-cp313-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "913784420b68a3d000179ee820c3041d4a6077a061571ae727c47e84e6841835",
"md5": "24bb7dfc3d8e7beed02e77694ffa44a1",
"sha256": "cdd1e066dae8b38eb48f0f294b99a210f0f6ca2bf29c846851f903a48d480c1b"
},
"downloads": -1,
"filename": "dry_webview-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "24bb7dfc3d8e7beed02e77694ffa44a1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 48476,
"upload_time": "2024-12-09T01:43:39",
"upload_time_iso_8601": "2024-12-09T01:43:39.643765Z",
"url": "https://files.pythonhosted.org/packages/91/37/84420b68a3d000179ee820c3041d4a6077a061571ae727c47e84e6841835/dry_webview-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-09 01:43:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "barradasotavio",
"github_project": "dry",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "dry-webview"
}