#python #tauri #back-end #rust

sys tauri-plugin-python

A tauri 2 plugin to use python code in the backend

1 unstable release

0.2.1 Jan 4, 2025

#451 in GUI

Download history 138/week @ 2025-01-01 13/week @ 2025-01-08

151 downloads per month

MIT license

35KB
632 lines

Tauri Plugin Python

This tauri plugin is supposed to make it easy to use Python as backend code. It uses PyO3 to call python from rust. The plugin reads by default the file src-tauri/src-python/main.py during startup and runs it immediately. Python functions are then registered during initialization and can get called during application workflow.

Platform Supported
Linux
Windows
macOS
Android not yet
iOS not yet

You might use this plugin to create simple prototype applications and later re-write functions in rust to improve performance, add a specific rust library or just call some low-level code.

Android and iOS are possible in theory but I still need to figure out how to cross compile python and PyO3 for iOS and android.

Also, this plugin hasn't been optimized yet for production binaries. The target platform therefore either needs to have libpython installed or you manually need to ship the shared libs together with the installer package.

Example app

There is a sample Desktop application for Windows/Linux/MacOS using this plugin and vanilla Javascript in examples/plain-javascript

Security considerations

Generally, this plugin has been created by "security by default" concept. Python functions can onl be called if registered from rust.

Keep in mind that this plugin can make it possible to run arbitrary python code. It is therefore highly recommended to not make the user interface accessible by a network URL.

The "runPython" command is disabled by default via permissions. If enabled, it is possible to inject python code via javascript. Also, the function "register" is disabled by default. If enabled, it can add control from javascript which functions can be called. This avoids to modify rust code when changing or adding python code. Both functions can be enabled during development for rapid prototyping.

Dependencies

~20–60MB
~899K SLoC