Skip to content

pytauri.ffi.lib

tauri::self

Classes:

Name Description
App
AppHandle
BuilderArgs
Builder
Context
RunEvent
RunEventEnum

Functions:

Name Description
builder_factory

A factory function for creating a Builder instance.

context_factory

A factory function for creating a Context instance.

Attributes:

Name Type Description
RunEventEnumType TypeAlias

See RunEventEnum for details.

__all__ module-attribute

__all__ = ['App', 'AppHandle', 'Builder', 'BuilderArgs', 'Context', 'RunEvent', 'RunEventEnum', 'RunEventEnumType', 'builder_factory', 'context_factory']

RunEventEnumType module-attribute

See RunEventEnum 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_iteration

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

cleanup_before_exit

Runs necessary cleanup tasks before exiting the process.

run

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

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

Warning

If callback is specified, it must not raise an exception, otherwise it is 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, /) -> None:
    """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.

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

run_iteration

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

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
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.**
    """

AppHandle

BuilderArgs

Methods:

Name Description
__new__

__new__

__new__(*, context: Context, invoke_handler: Optional[_InvokeHandlerProto] = None) -> Self

tauri::Builder

Warning

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

Parameters:

Name Type Description Default

context

Context

use context_factory to get it.

required

invoke_handler

Optional[_InvokeHandlerProto]

use Commands to get it.

None
Source code in python/pytauri/src/pytauri/ffi/lib.py
def __new__(
    cls,
    /,
    *,
    context: "Context",
    invoke_handler: Optional[_InvokeHandlerProto] = None,
) -> Self:
    """[tauri::Builder](https://docs.rs/tauri/latest/tauri/struct.Builder.html)

    !!! warning
        The implementer of `invoke_handler` must never raise an exception,
        otherwise it is considered undefined behavior.
        Additionally, `invoke_handler` must not block.

    Args:
        context: use [context_factory][pytauri.context_factory] to get it.
        invoke_handler: use [Commands][pytauri.ipc.Commands] to get it.
    """
    ...

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

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

build

build(args: BuilderArgs) -> App

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

Source code in python/pytauri/src/pytauri/ffi/lib.py
def build(self, args: BuilderArgs, /) -> App:
    """Consume this builder and build an app with the given `BuilderArgs`."""
    ...

Context

RunEvent

Bases: PyMatchRefMixin['RunEventEnumType']

tauri::RunEvent

Methods:

Name Description
match_ref

Equivalent to match &self in Rust.

match_ref

match_ref() -> _T

Equivalent to match &self in Rust.

Source code in python/pyo3-utils/src/pyo3_utils/__init__.py
def match_ref(self, /) -> _T:
    """Equivalent to `match &self` in Rust."""
    ...

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.
    """
    ...