Skip to content

pytauri.ffi.lib

tauri::self

Classes:

Name Description
App
AppHandle
Builder
Context
RunEvent
ExitRequestApi
CloseRequestApi
DragDropEvent
WebviewEvent
WindowEvent
Manager
Event
Listener
Position
Size
Rect
EventTarget
Emitter
Theme
BuilderArgs
Assets

Functions:

Name Description
webview_version
builder_factory

A factory function for creating a Builder instance.

context_factory

A factory function for creating a Context instance.

Attributes:

Name Type Description
RESTART_EXIT_CODE Final[int]
VERSION Final[LiteralString]
IS_DEV Final[bool]
RunEventType

See RunEvent for details.

DragDropEventType

See DragDropEvent for details.

WebviewEventType

See WebviewEvent for details.

WindowEventType

See WindowEvent for details.

ImplManager
EventId
ImplListener
PositionType

See Position for details.

SizeType

See Size for details.

Url
ImplEmitter
EventTargetType

See EventTarget for details.

__all__ module-attribute

__all__ = ['IS_DEV', 'RESTART_EXIT_CODE', 'VERSION', 'App', 'AppHandle', 'Assets', 'Builder', 'BuilderArgs', 'CloseRequestApi', 'Context', 'DragDropEvent', 'DragDropEventType', 'Emitter', 'Event', 'EventId', 'EventTarget', 'EventTargetType', 'ExitRequestApi', 'ImplEmitter', 'ImplListener', 'ImplManager', 'Listener', 'Manager', 'Position', 'PositionType', 'Rect', 'RunEvent', 'RunEventType', 'Size', 'SizeType', 'Theme', 'Url', 'WebviewEvent', 'WebviewEventType', 'WindowEvent', 'WindowEventType', 'builder_factory', 'context_factory', 'webview_version']

RESTART_EXIT_CODE module-attribute

RESTART_EXIT_CODE: Final[int] = RESTART_EXIT_CODE

tauri::RESTART_EXIT_CODE

The exit code on RunEvent::ExitRequested when AppHandle is called.

VERSION module-attribute

VERSION: Final[LiteralString] = VERSION

tauri::VERSION

The Tauri version.

IS_DEV module-attribute

IS_DEV: Final[bool] = IS_DEV

tauri::is_dev

Whether we are running in development mode or not.

RunEventType module-attribute

See RunEvent for details.

DragDropEventType module-attribute

DragDropEventType = TypeAliasType('DragDropEventType', Union[Enter, Over, Drop, Leave, _NonExhaustive])

See DragDropEvent for details.

WebviewEventType module-attribute

WebviewEventType = TypeAliasType('WebviewEventType', Union[DragDrop, _NonExhaustive])

See WebviewEvent for details.

WindowEventType module-attribute

WindowEventType = TypeAliasType('WindowEventType', Union[Resized, Moved, CloseRequested, Destroyed, Focused, ScaleFactorChanged, DragDrop, ThemeChanged, _NonExhaustive])

See WindowEvent for details.

ImplManager module-attribute

ImplManager = TypeAliasType('ImplManager', Union[App, AppHandle, 'WebviewWindow'])

EventId module-attribute

EventId = NewType('EventId', int)

ImplListener module-attribute

ImplListener = ImplManager

PositionType module-attribute

PositionType = TypeAliasType('PositionType', Union[Physical, Logical])

See Position for details.

SizeType module-attribute

SizeType = TypeAliasType('SizeType', Union[Physical, Logical])

See Size for details.

Url module-attribute

Url = TypeAliasType('Url', str)

ImplEmitter module-attribute

ImplEmitter = ImplManager

EventTargetType module-attribute

EventTargetType = TypeAliasType('EventTargetType', Union[Any, AnyLabel, App, Window, Webview, WebviewWindow, _NonExhaustive])

See EventTarget for details.

App

Tauri::app

Warning

This class is not thread-safe, and should not be shared between threads.

  • You can only use it on the thread it was created on.
  • And you need to ensure it is garbage collected on the thread it was created on, otherwise it will cause memory leaks.

Methods:

Name Description
run

Consume and run this app, will block until the app is exited.

run_return

Consume and run this application, returning its intended exit code.

run_iteration

Run this app iteratively without consuming it, calling callback on each iteration.

cleanup_before_exit

Runs necessary cleanup tasks before exiting the process.

handle

Get a handle to this app, which can be used to interact with the app from another thread.

run

run(callback: Optional[_AppRunCallbackType] = None) -> NoReturn

Consume and run this app, will block until the app is exited.

Parameters:

Name Type Description Default

callback

Optional[_AppRunCallbackType]

a callback function that will be called on each event. It will be called on the same thread that the app was created on, so you should not block in this function.

None

Note

This function will call std::process::exit at the end to terminate the entire process, which means the Python interpreter cannot be properly finalized. If this is a problem for you, please use pytauri.App.run_return.

Warning

If callback is specified, it must not raise an exception, otherwise it is logical undefined behavior, and in most cases, the program will panic.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def run(self, callback: Optional[_AppRunCallbackType] = None, /) -> NoReturn:
    """Consume and run this app, will block until the app is exited.

    Args:
        callback: a callback function that will be called on each event.
            It will be called on the same thread that the app was created on,
            so you should not block in this function.

    !!! note
        This function will call `std::process::exit` at the end to terminate the entire process,
        which means the Python interpreter cannot be properly finalized.
        If this is a problem for you, please use [pytauri.App.run_return][].

    !!! warning
        If `callback` is specified, it must not raise an exception,
        otherwise it is logical undefined behavior, and in most cases, the program will panic.
    """
    ...

run_return

run_return(callback: Optional[_AppRunCallbackType] = None) -> int

Consume and run this application, returning its intended exit code.

Warning

callback has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def run_return(self, callback: Optional[_AppRunCallbackType] = None, /) -> int:
    """Consume and run this application, returning its intended exit code.

    !!! warning
        `callback` has the same restrictions as [App.run][pytauri.App.run].
    """
    ...

run_iteration deprecated

run_iteration(callback: Optional[_AppRunCallbackType] = None) -> None
Deprecated

When called in a loop (as suggested by the name), this function will busy-loop. To re-gain control of control flow after the app has exited, use App::run_return instead. See https://docs.rs/tauri/latest/tauri/struct.App.html#method.run_iteration for more details.

Run this app iteratively without consuming it, calling callback on each iteration.

Parameters:

Name Type Description Default

callback

Optional[_AppRunCallbackType]

a callback function that will be called on each iteration.

None

Warning

callback has the same restrictions as App.run.

Tip

Approximately 2ms per calling in debug mode.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@deprecated(
    """When called in a loop (as suggested by the name), this function will busy-loop.
    To re-gain control of control flow after the app has exited, use `App::run_return` instead.
    See <https://docs.rs/tauri/latest/tauri/struct.App.html#method.run_iteration> for more details.""",
    category=None,
)
def run_iteration(
    self, callback: Optional[_AppRunCallbackType] = None, /
) -> None:
    """Run this app iteratively without consuming it, calling `callback` on each iteration.

    Args:
        callback: a callback function that will be called on each iteration.

    !!! warning
        `callback` has the same restrictions as [App.run][pytauri.App.run].

    !!! tip
        Approximately 2ms per calling in debug mode.
    """

cleanup_before_exit

cleanup_before_exit() -> None

Runs necessary cleanup tasks before exiting the process.

You should always exit the tauri app immediately after this function returns and not use any tauri-related APIs.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def cleanup_before_exit(self, /) -> None:
    """Runs necessary cleanup tasks before exiting the process.

    **You should always exit the tauri app immediately after this function returns and not use any tauri-related APIs.**
    """

handle

handle() -> AppHandle

Get a handle to this app, which can be used to interact with the app from another thread.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def handle(self, /) -> "AppHandle":
    """Get a handle to this app, which can be used to interact with the app from another thread."""
    ...

AppHandle

tauri::AppHandle

Methods:

Name Description
run_on_main_thread

Runs the given closure on the main thread.

exit
restart
on_menu_event

Registers a global menu event listener.

on_tray_icon_event

Registers a global tray icon menu event listener.

tray_by_id
remove_tray_by_id
set_theme
default_window_icon

Returns the default window icon.

menu
set_menu
remove_menu
hide_menu
show_menu
invoke_key

run_on_main_thread

run_on_main_thread(handler: Callable[[], object]) -> None

Runs the given closure on the main thread.

Warning

handler has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def run_on_main_thread(self, handler: Callable[[], object], /) -> None:
    """Runs the given closure on the main thread.

    !!! warning
        `handler` has the same restrictions as [App.run][pytauri.App.run].
    """
    ...

exit

exit(exit_code: int) -> None
Source code in python/pytauri/src/pytauri/ffi/lib.py
def exit(self, exit_code: int, /) -> None: ...

restart

restart() -> Never
Source code in python/pytauri/src/pytauri/ffi/lib.py
def restart(self, /) -> Never: ...

on_menu_event

on_menu_event(handler: Callable[[Self, MenuEvent], None]) -> None

Registers a global menu event listener.

Warning

handler has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def on_menu_event(
    self, handler: Callable[["Self", "MenuEvent"], None], /
) -> None:
    """Registers a global menu event listener.

    !!! warning
        `handler` has the same restrictions as [App.run][pytauri.App.run].
    """

on_tray_icon_event

on_tray_icon_event(handler: Callable[[Self, TrayIconEventType], None]) -> None

Registers a global tray icon menu event listener.

Warning

handler has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def on_tray_icon_event(
    self, handler: Callable[[Self, TrayIconEventType], None], /
) -> None:
    """Registers a global tray icon menu event listener.

    !!! warning
        `handler` has the same restrictions as [App.run][pytauri.App.run].
    """

tray_by_id

tray_by_id(id: str) -> Optional[TrayIcon]
Source code in python/pytauri/src/pytauri/ffi/lib.py
def tray_by_id(self, id: str, /) -> Optional[TrayIcon]: ...  # noqa: A002

remove_tray_by_id

remove_tray_by_id(id: str) -> Optional[TrayIcon]
Source code in python/pytauri/src/pytauri/ffi/lib.py
def remove_tray_by_id(self, id: str, /) -> Optional[TrayIcon]: ...  # noqa: A002

set_theme

set_theme(theme: Optional[Theme]) -> None
Source code in python/pytauri/src/pytauri/ffi/lib.py
def set_theme(self, theme: Optional["Theme"], /) -> None: ...

default_window_icon

default_window_icon() -> Optional[Image]

Returns the default window icon.

Warning

Each time you call this function, a new image instance will be created. So you should cache the result if you need to use it multiple times.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def default_window_icon(self, /) -> Optional[Image]:
    """Returns the default window icon.

    !!! warning
        Each time you call this function, a new image instance will be created.
        So you should cache the result if you need to use it multiple times.
    """

menu

menu() -> Optional[Menu]
Source code in python/pytauri/src/pytauri/ffi/lib.py
def menu(self) -> Optional[Menu]: ...

set_menu

set_menu(menu: Menu) -> Optional[Menu]
Source code in python/pytauri/src/pytauri/ffi/lib.py
def set_menu(self, menu: Menu, /) -> Optional[Menu]: ...

remove_menu

remove_menu() -> Optional[Menu]
Source code in python/pytauri/src/pytauri/ffi/lib.py
def remove_menu(self) -> Optional[Menu]: ...

hide_menu

hide_menu() -> None
Source code in python/pytauri/src/pytauri/ffi/lib.py
def hide_menu(self) -> None: ...

show_menu

show_menu() -> None
Source code in python/pytauri/src/pytauri/ffi/lib.py
def show_menu(self) -> None: ...

invoke_key

invoke_key() -> str
Source code in python/pytauri/src/pytauri/ffi/lib.py
def invoke_key(self) -> str: ...

Builder

tauri::Builder

use builder_factory to instantiate this class.

Warning

This class is not thread-safe, and should not be shared between threads.

  • You can only use it on the thread it was created on.
  • And you need to ensure it is garbage collected on the thread it was created on, otherwise it will cause memory leaks.

Methods:

Name Description
build

build

tauri::Builder::build

Consume this builder and build an app with the given BuilderArgs.

Parameters:

Name Type Description Default

context

Context

use context_factory to get it.

required

**kwargs

Unpack[BuilderArgs]

see BuilderArgs for details.

{}
Source code in python/pytauri/src/pytauri/ffi/lib.py
def build(self, context: "Context", **kwargs: Unpack["BuilderArgs"]) -> App:
    """[tauri::Builder::build](https://docs.rs/tauri/latest/tauri/struct.Builder.html#method.build)

    Consume this builder and build an app with the given `BuilderArgs`.

    Args:
        context: use [context_factory][pytauri.context_factory] to get it.
        **kwargs: see [BuilderArgs][pytauri.BuilderArgs] for details.
    """
    ...

Context

tauri::Context

Methods:

Name Description
set_assets

Use custom assets instead of the assets bundled by Tauri.

set_assets

set_assets(assets: Assets) -> None

Use custom assets instead of the assets bundled by Tauri.

To make this work:

  • You need to enable the tauri/custom-protocol feature.
    • Or build using tauri build.
  • Set frontendDist in tauri.conf.json to an empty directory (do not set it to a URL).
    • Or generate Context via:

      use tauri::{generate_context, test::noop_assets};
      
      let context = generate_context!(assets=noop_assets());
      

      then we will use this method to set the assets.

      see: https://github.com/tauri-apps/tauri/pull/9141

Source code in python/pytauri/src/pytauri/ffi/lib.py
def set_assets(self, assets: "Assets", /) -> None:
    """Use custom assets instead of the assets bundled by Tauri.

    To make this work:

    - You need to enable the `tauri/custom-protocol` feature.
        - Or build using `tauri build`.
    - Set `frontendDist` in `tauri.conf.json` to an empty directory (do not set it to a URL).
        - Or generate `Context` via:

            ```rust
            use tauri::{generate_context, test::noop_assets};

            let context = generate_context!(assets=noop_assets());
            ```

            then we will use this method to set the assets.

            see: <https://github.com/tauri-apps/tauri/pull/9141>
    """

RunEvent

tauri::RunEvent

Classes:

Name Description
Exit
ExitRequested
WindowEvent
WebviewEvent
Ready
Resumed
MainEventsCleared
MenuEvent
TrayIconEvent

ExitRequested

tauri::RunEvent::ExitRequested

Attributes:

Name Type Description
code Optional[int]
api ExitRequestApi

code instance-attribute

code: Optional[int]

api instance-attribute

WindowEvent

tauri::RunEvent::WindowEvent

Attributes:

Name Type Description
label str
event WindowEventType

label instance-attribute

label: str

event instance-attribute

WebviewEvent

tauri::RunEvent::WebviewEvent

Attributes:

Name Type Description
label str
event WebviewEventType

label instance-attribute

label: str

event instance-attribute

MenuEvent

Bases: tuple[MenuEvent]

tauri::RunEvent::MenuEvent

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: MenuEvent) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: MenuEvent, /) -> Self: ...

TrayIconEvent

Bases: tuple[TrayIconEventType]

tauri::RunEvent::TrayIconEvent

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: TrayIconEventType) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: TrayIconEventType, /) -> Self: ...

ExitRequestApi

tauri::ExitRequestApi

Methods:

Name Description
prevent_exit

prevent_exit

prevent_exit() -> None
Source code in python/pytauri/src/pytauri/ffi/lib.py
def prevent_exit(self, /) -> None: ...

CloseRequestApi

tauri::CloseRequestApi

Methods:

Name Description
prevent_close

prevent_close

prevent_close() -> None
Source code in python/pytauri/src/pytauri/ffi/lib.py
def prevent_close(self, /) -> None: ...

DragDropEvent

tauri::DragDropEvent

Classes:

Name Description
Enter
Over
Drop
Leave

Enter

tauri::DragDropEvent::Enter

Attributes:

Name Type Description
paths _VecPathBuf
position _PhysicalPositionF64

paths instance-attribute

paths: _VecPathBuf

position instance-attribute

position: _PhysicalPositionF64

Over

tauri::DragDropEvent::Over

Attributes:

Name Type Description
position _PhysicalPositionF64

position instance-attribute

position: _PhysicalPositionF64

Drop

tauri::DragDropEvent::Drop

Attributes:

Name Type Description
paths _VecPathBuf
position _PhysicalPositionF64

paths instance-attribute

paths: _VecPathBuf

position instance-attribute

position: _PhysicalPositionF64

WebviewEvent

tauri::WebviewEvent

Classes:

Name Description
DragDrop

DragDrop

Bases: tuple['DragDropEventType']

tauri::WebviewEvent::DragDrop

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: DragDropEventType) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: "DragDropEventType", /) -> Self: ...

WindowEvent

tauri::WindowEvent

Classes:

Name Description
Resized
Moved
CloseRequested
Destroyed
Focused
ScaleFactorChanged
DragDrop
ThemeChanged

Resized

Bases: tuple[_PhysicalSizeU32]

tauri::WindowEvent::Resized

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: _PhysicalSizeU32) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: _PhysicalSizeU32, /) -> Self: ...

Moved

Bases: tuple[_PhysicalPositionI32]

tauri::WindowEvent::Moved

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: _PhysicalPositionI32) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: _PhysicalPositionI32, /) -> Self: ...

CloseRequested

tauri::WindowEvent::CloseRequested

Attributes:

Name Type Description
api CloseRequestApi

api instance-attribute

Focused

Bases: tuple[bool]

tauri::WindowEvent::Focused

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: bool) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: bool, /) -> Self: ...

ScaleFactorChanged

tauri::WindowEvent::ScaleFactorChanged

Attributes:

Name Type Description
scale_factor float
new_inner_size _PhysicalSizeU32

scale_factor instance-attribute

scale_factor: float

new_inner_size instance-attribute

new_inner_size: _PhysicalSizeU32

DragDrop

Bases: tuple['DragDropEventType']

tauri::WindowEvent::DragDrop

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: DragDropEventType) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: "DragDropEventType", /) -> Self: ...

ThemeChanged

Bases: tuple['Theme']

tauri::WindowEvent::ThemeChanged

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: Theme) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: "Theme", /) -> Self: ...

Manager

tauri::Manager

Methods:

Name Description
app_handle

The application handle associated with this manager.

get_webview_window

Fetch a single webview window from the manager.

webview_windows

Fetch all managed webview windows.

manage

Add state to the state managed by the application.

state

Retrieves the managed state for the type T.

try_state

Attempts to retrieve the managed state for the type T.

path

The path resolver is a helper class for general and application-specific path APIs.

app_handle staticmethod

app_handle(slf: ImplManager) -> AppHandle

The application handle associated with this manager.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def app_handle(slf: "ImplManager", /) -> AppHandle:
    """The application handle associated with this manager."""
    ...

get_webview_window staticmethod

get_webview_window(slf: ImplManager, label: str) -> Optional[WebviewWindow]

Fetch a single webview window from the manager.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def get_webview_window(
    slf: "ImplManager", label: str, /
) -> Optional[WebviewWindow]:
    """Fetch a single webview window from the manager."""
    ...

webview_windows staticmethod

webview_windows(slf: ImplManager) -> dict[str, WebviewWindow]

Fetch all managed webview windows.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def webview_windows(slf: "ImplManager", /) -> dict[str, WebviewWindow]:
    """Fetch all managed webview windows."""
    ...

manage staticmethod

manage(slf: ImplManager, state: object) -> bool

Add state to the state managed by the application.

If the state for the T type has previously been set, the state is unchanged and false is returned. Otherwise true is returned.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def manage(slf: "ImplManager", state: object, /) -> bool:
    """Add `state` to the state managed by the application.

    If the state for the `T` type has previously been set, the state is unchanged and false is returned.
    Otherwise true is returned.
    """
    ...

state staticmethod

state(slf: ImplManager, state_type: type[_T]) -> _T

Retrieves the managed state for the type T.

Raises:

Type Description
Exception

Panics if the state for the type T has not been previously managed. Use try_state for a non-panicking version.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def state(slf: "ImplManager", state_type: type[_T], /) -> _T:
    """Retrieves the managed state for the type `T`.

    Raises:
        Exception: Panics if the state for the type `T` has not been previously [managed][pytauri.ffi.lib.Manager].
            Use [try_state][pytauri.ffi.lib.Manager.try_state] for a non-panicking version.
    """
    ...

try_state staticmethod

try_state(slf: ImplManager, state_type: type[_T]) -> Optional[_T]

Attempts to retrieve the managed state for the type T.

Returns Some if the state has previously been managed. Otherwise returns None.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def try_state(slf: "ImplManager", state_type: type[_T], /) -> Optional[_T]:
    """Attempts to retrieve the managed state for the type `T`.

    Returns `Some` if the state has previously been `managed`. Otherwise returns `None`.
    """
    ...

path staticmethod

path(slf: ImplManager) -> PathResolver

The path resolver is a helper class for general and application-specific path APIs.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def path(slf: "ImplManager", /) -> PathResolver:
    """The path resolver is a helper class for general and application-specific path APIs."""
    ...

Event

tauri::Event

Attributes:

Name Type Description
id EventId

The EventId of the handler that was triggered.

payload str

The event payload.

id property

id: EventId

The EventId of the handler that was triggered.

payload property

payload: str

The event payload.

Listener

tauri::Listener

See also: https://tauri.app/develop/calling-rust/#event-system

Examples

from pydantic import BaseModel
from pytauri import AppHandle, Event, Listener


class Payload(BaseModel):  # or `RootModel`
    url: str
    num: int


def listen(app_handle: AppHandle) -> None:
    def handler(event: Event):
        assert event.id == event_id

        serialized_event = Payload.model_validate_json(event.payload)
        print(serialized_event.url, serialized_event.num)

    event_id = Listener.listen(app_handle, "event_name", handler)

Methods:

Name Description
listen

Listen to an emitted event on this manager.

once

Listen to an event on this manager only once.

unlisten

Remove an event listener.

listen_any

Listen to an emitted event to any target.

once_any

Listens once to an emitted event to any target .

listen staticmethod

listen(slf: ImplListener, event: str, handler: _EventHandlerType) -> EventId

Listen to an emitted event on this manager.

Warning

handler has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def listen(
    slf: "ImplListener",
    event: str,
    handler: _EventHandlerType,
    /,
) -> "EventId":
    """Listen to an emitted event on this manager.

    !!! warning
        `handler` has the same restrictions as [App.run][pytauri.App.run].
    """
    ...

once staticmethod

once(slf: ImplListener, event: str, handler: _EventHandlerType) -> EventId

Listen to an event on this manager only once.

Warning

handler has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def once(
    slf: "ImplListener",
    event: str,
    handler: _EventHandlerType,
    /,
) -> "EventId":
    """Listen to an event on this manager only once.

    !!! warning
        `handler` has the same restrictions as [App.run][pytauri.App.run].
    """
    ...

unlisten staticmethod

unlisten(slf: ImplListener, id: EventId) -> None

Remove an event listener.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def unlisten(
    slf: "ImplListener",
    id: "EventId",  # noqa: A002
    /,
) -> None:
    """Remove an event listener."""
    ...

listen_any staticmethod

listen_any(slf: ImplListener, event: str, handler: _EventHandlerType) -> EventId

Listen to an emitted event to any target.

Warning

handler has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def listen_any(
    slf: "ImplListener",
    event: str,
    handler: _EventHandlerType,
    /,
) -> "EventId":
    """Listen to an emitted event to any target.

    !!! warning
        `handler` has the same restrictions as [App.run][pytauri.App.run].
    """
    ...

once_any staticmethod

once_any(slf: ImplListener, event: str, handler: _EventHandlerType) -> EventId

Listens once to an emitted event to any target .

Warning

handler has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def once_any(
    slf: "ImplListener",
    event: str,
    handler: _EventHandlerType,
    /,
) -> "EventId":
    """Listens once to an emitted event to any target .

    !!! warning
        `handler` has the same restrictions as [App.run][pytauri.App.run].
    """
    ...

Position

tauri::Position

Classes:

Name Description
Physical
Logical

Physical

Bases: tuple[_PhysicalPositionI32]

tauri::Position::Physical

Warning

This is actually a Class disguised as an NamedTuple. See also: https://pyo3.rs/v0.23.4/class.html#pyclass-enums.

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: _PhysicalPositionI32) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: _PhysicalPositionI32, /) -> Self: ...

Logical

Bases: tuple[_LogicalPositionF64]

tauri::Position::Logical

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: _LogicalPositionF64) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: _LogicalPositionF64, /) -> Self: ...

Size

tauri::Size

Classes:

Name Description
Physical
Logical

Physical

Bases: tuple[_PhysicalSizeU32]

tauri::Size::Physical

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: _PhysicalSizeU32) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: _PhysicalSizeU32, /) -> Self: ...

Logical

Bases: tuple[_LogicalSizeF64]

tauri::Size::Logical

Methods:

Name Description
__new__

Attributes:

Name Type Description
__match_args__

__match_args__ class-attribute instance-attribute

__match_args__ = ('_0',)

__new__

__new__(_0: _LogicalSizeF64) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, _0: _LogicalSizeF64, /) -> Self: ...

Rect

tauri::Rect

Methods:

Name Description
__new__

Attributes:

Name Type Description
position PositionType
size SizeType

position property

position: PositionType

size property

size: SizeType

__new__

__new__(*, position: PositionType, size: SizeType) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(
    cls,
    /,
    *,
    position: "PositionType",
    size: "SizeType",
) -> Self: ...

EventTarget

tauri::EventTarget

Classes:

Name Description
Any

Any and all event targets.

AnyLabel

Any Window, Webview or WebviewWindow that have this label.

App

App and AppHandle targets.

Window

Window target.

Webview

Webview target.

WebviewWindow

WebviewWindow target.

Any

Any and all event targets.

Methods:

Name Description
__new__

__new__

__new__() -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, /) -> Self: ...

AnyLabel

Any Window, Webview or WebviewWindow that have this label.

Methods:

Name Description
__new__

Attributes:

Name Type Description
label str

Target label.

label instance-attribute

label: str

Target label.

__new__

__new__(label: str) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, label: str, /) -> Self: ...

App

App and AppHandle targets.

Methods:

Name Description
__new__

__new__

__new__() -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, /) -> Self: ...

Window

Window target.

Methods:

Name Description
__new__

Attributes:

Name Type Description
label str

window label.

label instance-attribute

label: str

window label.

__new__

__new__(label: str) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, label: str, /) -> Self: ...

Webview

Webview target.

Methods:

Name Description
__new__

Attributes:

Name Type Description
label str

webview label.

label instance-attribute

label: str

webview label.

__new__

__new__(label: str) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, label: str, /) -> Self: ...

WebviewWindow

WebviewWindow target.

Methods:

Name Description
__new__

Attributes:

Name Type Description
label str

webview window label.

label instance-attribute

label: str

webview window label.

__new__

__new__(label: str) -> Self
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(cls, label: str, /) -> Self: ...

Emitter

tauri::Emitter

Methods:

Name Description
emit_str

Similar to [Emitter::emit] but the payload is json serialized.

emit_str_to

Similar to [Emitter::emit_to] but the payload is json serialized.

emit_str_filter

Similar to [Emitter::emit_filter] but the payload is json serialized.

emit_str staticmethod

emit_str(slf: ImplEmitter, event: str, payload: str) -> None

Similar to [Emitter::emit] but the payload is json serialized.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def emit_str(
    slf: "ImplEmitter",
    event: str,
    payload: str,
    /,
) -> None:
    """Similar to [`Emitter::emit`] but the payload is json serialized."""
    ...

emit_str_to staticmethod

emit_str_to(slf: ImplEmitter, target: EventTargetType, event: str, payload: str) -> None

Similar to [Emitter::emit_to] but the payload is json serialized.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def emit_str_to(
    slf: "ImplEmitter",
    target: "EventTargetType",
    event: str,
    payload: str,
    /,
) -> None:
    """Similar to [`Emitter::emit_to`] but the payload is json serialized."""
    ...

emit_str_filter staticmethod

emit_str_filter(slf: ImplEmitter, event: str, payload: str, filter: Callable[[EventTargetType], bool]) -> None

Similar to [Emitter::emit_filter] but the payload is json serialized.

Warning

filter has the same restrictions as App.run.

Source code in python/pytauri/src/pytauri/ffi/lib.py
@staticmethod
def emit_str_filter(
    slf: "ImplEmitter",
    event: str,
    payload: str,
    filter: Callable[["EventTargetType"], bool],  # noqa: A002
    /,
) -> None:
    """Similar to [`Emitter::emit_filter`] but the payload is json serialized.

    !!! warning
        `filter` has the same restrictions as [App.run][pytauri.App.run].
    """
    ...

Theme

Bases: Enum

tauri::Theme

Attributes:

Name Type Description
Light
Dark

Light class-attribute instance-attribute

Light = auto()

Dark class-attribute instance-attribute

Dark = auto()

BuilderArgs

Bases: TypedDict

tauri::Builder

Attributes:

Name Type Description
invoke_handler Required[Optional[_InvokeHandlerProto]]

Use Commands to get it.

setup Callable[[AppHandle], object]

See rust tauri::Builder::setup

invoke_handler instance-attribute

invoke_handler: Required[Optional[_InvokeHandlerProto]]

Use Commands to get it.

Warning

The implement of invoke_handler must never raise an exception, otherwise it is considered logical undefined behavior. Additionally, invoke_handler must not block.

Warning

If you do not specify invoke_handler, pytauri will not register the tauri-plugin-pytauri plugin, which means you cannot use pyInvoke in the frontend to call Commands (you will receive an error like "plugin pytauri not found"). If this is indeed the behavior you expect, explicitly pass None.

setup instance-attribute

See rust tauri::Builder::setup

Assets

Bases: ABC

tauri::Assets

This is an abstract class that you can subclass to implement a custom asset loader.

See tauri::Assets rust docs for more details.

Warning

The implement has the same restrictions as App.run.

Methods:

Name Description
get
iter
setup

get abstractmethod

get(key: _AssetKey) -> Optional[bytes]
Source code in python/pytauri/src/pytauri/ffi/lib.py
@abstractmethod
def get(self, key: _AssetKey, /) -> Optional[bytes]: ...

iter abstractmethod

iter() -> Iterator[tuple[str, bytes]]
Source code in python/pytauri/src/pytauri/ffi/lib.py
@abstractmethod
def iter(self, /) -> Iterator[tuple[str, bytes]]: ...

setup

setup(_app: AppHandle) -> object
Source code in python/pytauri/src/pytauri/ffi/lib.py
def setup(self, _app: AppHandle, /) -> object:
    return None

webview_version

webview_version() -> str

tauri::webview_version

Get WebView/Webkit version on current platform.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def webview_version() -> str:
    """[tauri::webview_version](https://docs.rs/tauri/latest/tauri/fn.webview_version.html)

    Get WebView/Webkit version on current platform.
    """
    ...

builder_factory

builder_factory(*args: Any, **kwargs: Any) -> Builder

A factory function for creating a Builder instance.

This is the closure passed from the Rust side when initializing the pytauri pyo3 module. args and kwargs will be passed to this closure.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def builder_factory(*args: Any, **kwargs: Any) -> Builder:
    """A factory function for creating a `Builder` instance.

    This is the closure passed from the Rust side when initializing the pytauri pyo3 module.
    `args` and `kwargs` will be passed to this closure.
    """
    ...

context_factory

context_factory(*args: Any, **kwargs: Any) -> Context

A factory function for creating a Context instance.

This is the closure passed from the Rust side when initializing the pytauri pyo3 module. args and kwargs will be passed to this closure.

Source code in python/pytauri/src/pytauri/ffi/lib.py
def context_factory(*args: Any, **kwargs: Any) -> Context:
    """A factory function for creating a `Context` instance.

    This is the closure passed from the Rust side when initializing the pytauri pyo3 module.
    `args` and `kwargs` will be passed to this closure.
    """
    ...