Using tauri plugins¶
The Tauri team and community have developed some plugins, you can use them by:
- Official Tauri plugins usually provide corresponding JavaScript APIs, which you can use directly on the frontend.
-
Write your own Rust functions using pyo3 and expose them to Python: https://github.com/pytauri/pytauri/discussions/45#discussioncomment-11870767
We encourage you to distribute plugins written in this way to benefit the entire community 💪.
In addition, PyTauri has already integrated some official Tauri plugins. Below, we use tauri-plugin-notification as an example to demonstrate how to use a PyTauri-integrated plugins.
All plugins we support¶
Plugin | JS Docs | Rust Docs | Python Docs |
---|---|---|---|
plugin-notification | JS docs | Rust docs | Python docs |
plugin-dialog | JS docs | Rust docs | Python docs |
Using the plugin¶
install tauri plugin¶
All PyTauri plugins are just Python bindings, which means you need to initialize the underlying Tauri extensions normally:
expose the pyo3 bingings to python¶
Enable the pytauri
feature:
[dependencies]
# ...
-pytauri = { version = "*" }
+pytauri = { version = "*", features = ["plugin-notification"] }
use plugin api from python¶
The PyTauri API maps very well to the original Rust API of the plugin. You can refer to the Js docs, Rust docs and Python docs to understand how to use it:
Tip
pytauri_plugins
is distributed as part of the pytauri
package on PyPI.
Therefore, running pip install pytauri
will also install it.
import sys
from pydantic import BaseModel
from pytauri import AppHandle, Commands
from pytauri_plugins.notification import NotificationExt
commands: Commands = Commands()
class Person(BaseModel):
name: str
class Greeting(BaseModel):
message: str
@commands.command()
async def greet(body: Person, app_handle: AppHandle) -> Greeting:
notification_builder = NotificationExt.builder(app_handle)
notification_builder.show(title="Greeting", body=f"Hello, {body.name}!")
return Greeting(
message=f"Hello, {body.name}! You've been greeted from Python {sys.version}!"
)