You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-1Lines changed: 34 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,8 +33,41 @@ or you manually need to ship the shared libs together with the installer package
33
33
There is a sample Desktop application for Windows/Linux/MacOS using this plugin and vanilla
34
34
Javascript in [examples/plain-javascript](https://github.com/marcomq/tauri-plugin-python/tree/main/examples/plain-javascript)
35
35
36
+
## Manual plugin installation / usage
37
+
38
+
These steps assume that you already have a basic tauri application available. Alternatively, you can immediately start with the example application.
39
+
40
+
-`$ cargo add tauri-plugin-python`
41
+
-`$ npm install tauri-plugin-python-api`
42
+
- modify `permissions:[]` in src-tauri/capabilities/default.json and add "python:default"
43
+
- add file `src-tauri/src-python/main.py` and add python code, for example:
44
+
```python
45
+
# src-tauri/src-python/main.py
46
+
defgreet_python(rust_var)
47
+
print(rust_var)
48
+
returnstr(rust_var) +" from python"
49
+
```
50
+
- add `.plugin(tauri_plugin_python::init(vec!["greet_python"))` to `tauri::Builder::default()`, usually in `src-tauri/src/lib.rs`. This will initialize the plugin and make the python function "greet_python" available from javascript.
51
+
- add javascript for python plugin in the index.html file directly or in your somewhere in your javascript application. For vanilla javascript / iife, the modules can be found in `window.__TAURI__.python`. For modern javascript:
-> this will call the python function "greet_python" with parameter "input value". Of course, you can just pass in any available javascript value. This should work with "boolean", "integer", "double", "string", "string[]", "double[]" parameter types.
You either need to have python installed on the target machine or ship the shared python library with your package. You also may link the python library statically - PyO3 may do this by default if it finds a static python library. In addition, you need to copy the python files so that python files are next to the binary. The file `src-python/main.py` is required for the plugin to work correctly. You may also add additional python files or use a venv environment. The included resources can be configurable in the `tauri.conf.json` file. Check the tauri and PyO3 documentation for additional info.
68
+
36
69
## Security considerations
37
-
Generally, this plugin has been created by "security by default" concept. Python functions can onl be called if registered from rust.
70
+
Generally, this plugin has been created by "security by default" concept. Python functions can only be called if registered from rust.
38
71
39
72
Keep in mind that this plugin can make it possible to run arbitrary python code.
40
73
It is therefore highly recommended to **not make the user interface accessible by a network URL**.
0 commit comments