Minimal Rust-Python example using PyO3.
make dev
make test
make buildfrom mvp import add, Calculator
# Add two numbers
add(5, 10)
# Use Calculator
calc = Calculator(5)
calc.get_value()
calc.add(10)Here's a quick demonstration of the development workflow with Rust and Python integration:
-
Add a debug print statement to the Rust code:
diff --git a/src/lib.rs b/src/lib.rs --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ impl Calculator { } fn add(&self, other: i64) -> PyResult<i64> { + println!("🦀 FROM RUST: Calculator adding {} to {}", other, self.value); Ok(self.value + other) }
-
Rebuild and run tests with stdout capturing disabled:
make rebuild; uv run py.test -x -s -
See the Rust println! output in your Python tests:
======= test session starts ======= collected 4 items tests/test_mvp.py .🦀 FROM RUST: Calculator adding 10 to 10 ..🦀 FROM RUST: Calculator adding 5 to 10 🦀 FROM RUST: Calculator adding 20 to 10 . ======= 4 passed in 0.01s =======
This demonstrates how you can debug Rust code using println! statements that will appear in your Python test output when using pytest's -s flag.
- nodejs-rust-mvp - A companion project showing Rust integration with Node.js using WebAssembly
This project is licensed under the MIT License - see the LICENSE file for details.