Skip to content

Using Tauri Plugins

The Tauri team and community have developed some plugins, you can use them by:

  1. Official Tauri plugins usually provide corresponding JavaScript APIs, which you can use directly on the frontend.
  2. 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 pytauri-integrated plugins.

All plugins we support

Plugin/Features JS Docs Rust Docs Python Docs
plugin-autostart JS docs Rust docs Python docs
plugin-clipboard-manager JS docs Rust docs Python docs
plugin-deep-link JS docs Rust docs Python docs
plugin-dialog JS docs Rust docs Python docs
plugin-fs JS docs Rust docs Python docs
plugin-global-shortcut JS docs Rust docs Python docs
plugin-http JS docs Rust docs Python docs
plugin-notification JS docs Rust docs Python docs
plugin-opener JS docs Rust docs Python docs
plugin-os JS docs Rust docs Python docs
plugin-persisted-scope - Rust docs Python docs
plugin-positioner JS docs Rust docs Python docs
plugin-process JS docs Rust docs Python docs
plugin-shell JS docs Rust docs Python docs
plugin-single-instance - Rust docs Python docs
plugin-updater JS docs Rust docs Python docs
plugin-upload JS docs Rust docs Python docs
plugin-websocket JS docs Rust docs Python docs
plugin-window-state 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:

pnpm tauri add notification

The above command will perform the following steps (which you can also do manually):

  • Add tauri-plugin-notification as a Rust dependency in Cargo.toml.
  • Add @tauri-apps/plugin-notification as a frontend dependency in package.json

    This step is optional

    If you only use the global API (window.__TAURI__.notification) on the frontend, you can skip this step.

  • Register the core plugin with tauri

    src-tauri/src/lib.rs
    // i.e., `builder_factory` function of python binding
    |_args, _kwargs| {
        let builder = tauri::Builder::default()
            .plugin(tauri_plugin_notification::init());  // 👈
        Ok(builder)
    },
    
    registering plugin from python

    Since pytauri v0.8, you can also register plugins directly from your Python code:

    src-tauri/python/tauri_app/__init__.py
    from pytauri import (
        builder_factory,
        context_factory,
    )
    from pytauri_plugins import notification
    
    app = builder_factory().build(
        context=context_factory(),
        invoke_handler=None,
        plugins=[notification.init()],  # 👈
    )
    

    This depends on your preference, but for pytauri_wheel, plugins can only be registered in this way (since you don't have access to the Rust code).

  • Add the permissions to your capabilities file

    src-tauri/capabilities/default.json
    {
        // ...
        "permissions": [
            // ...
            "notification:default"
        ],
    }
    

Expose the pyo3 bindings to python

Enable the pytauri feature:

src-tauri/Cargo.toml
[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 plugin-notification, 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.

src-tauri/python/tauri_app/__init__.py
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}!"
    )