Skip to content

Commit c449664

Browse files
committed
readme
1 parent 611ac4e commit c449664

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# async_py
22

3-
A Rust library for calling Python code asynchronously using `pyo3` and `tokio`.
3+
A Rust library for calling Python code asynchronously using [pyo3](https://github.com/PyO3/pyo3) and [tokio](https://tokio.rs/).
44

5-
This library provides a `PyRunner` that runs a Python interpreter in a dedicated background thread. Global variables will be kept and stored in this runner.
6-
You can send Python code to this executor from any async Rust task, and it will be executed without blocking your application.
5+
This library provides a `PyRunner` that runs a Python interpreter in a dedicated
6+
background thread. Global variables are preserved within the runner's scope.
7+
You can send Python code to this executor from any async Rust task,
8+
and it will be executed without blocking your application.
79

8-
Due to the Python global interpreter lock (GIL), there will not be any multithreading. If one python
10+
Due to the Python Global Interpreter Lock (GIL), you cannot run Python code simultaneously. If one Python
911
task is performing a computation or a sleep, no other task can access the interpreter.
1012

11-
Using multiple `PyRunner` does not allow multithreading, due to the architecture
12-
of python. But you can isolate your global variables by using multiple runners.
13+
Using multiple `PyRunner` instances does not enable simultaneous Python code execution due to the GIL.
14+
However, it does allow you to isolate global variables between different runners.
1315

1416
## Usage
1517

1618
Add `async_py` to your `Cargo.toml`:
1719

1820
```toml
1921
[dependencies]
20-
async_py = { git = "..." } # Or path, or crates.io version
22+
async_py = { git = "https://github.com/marcomq/async_py" } # Or path, or crates.io version
2123
tokio = { version = "1", features = ["full"] }
2224
```
2325

@@ -48,3 +50,24 @@ def greet(name):
4850
println!("{}", result2.as_str().unwrap()); // Prints: Hello World! Called 2 times from Python.
4951
}
5052
```
53+
### Using a venv
54+
It is generally recommended to use a venv to install pip packages.
55+
While you cannot switch the interpreter version with this crate, you can use an
56+
existing venv to load installed packages.
57+
58+
```rust
59+
let runner = PyRunner::new();
60+
runner.set_venv(&Path::new("/path/to/venv")).await?;
61+
```
62+
63+
### rustpython
64+
PyO3 has usually the best compatibility for python packages.
65+
But if you want to use python on android, wasm, or if you don't want to use any
66+
external library, you can use [rustpython](https://github.com/RustPython/RustPython).
67+
Keep in mind that some essential packages like `os` are missing on rustpython.
68+
69+
Cargo.toml
70+
```toml
71+
[dependencies]
72+
async_py = { features = ["rustpython"] }
73+
```

0 commit comments

Comments
 (0)