Skip to content

Commit 18d622d

Browse files
committed
tweak py03 blog post
1 parent d3eed95 commit 18d622d

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

content/bridging-python-and-rust.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
+++
22
title = "Bridging Python & Rust: A Walkthrough of using Py03"
33
date = 2025-05-18
4+
updated = 2025-08-30
45
description = "A practical guide to exposing Rust functions to Python using PyO3."
56

67
[taxonomies]
@@ -17,7 +18,7 @@ tags = ["rust", "python", "py03"]
1718

1819
# Bridging Python and Rust: A Practical Guide with PyO3
1920

20-
Sometimes Python just isn't fast enough, or you want to reuse some Rust code without rewriting it. [PyO3](https://pyo3.rs) makes it surprisingly easy to call Rust from Python (or less commonly vice-versa). Here’s how I created [pngme-python][1] crate, to expose my already existinv [pngme][2] Rust crate.
21+
Sometimes Python just isn't fast enough, or you want to reuse some Rust code without rewriting it. [PyO3](https://pyo3.rs) makes it surprisingly easy to call Rust from Python (or less commonly vice-versa). Here’s how I created [pngme-python][1] crate, to expose my already existing [pngme][2] Rust crate as a python library.
2122

2223
## Project Structure
2324

@@ -114,13 +115,13 @@ mod pngme_python {
114115

115116
The key parts of this implementation:
116117

117-
- The `#[pymodule]` macro creates a Python module
118-
- Each `#[pyfunction]` exposes a Rust function to Python
119-
- Rust error types are mapped to appropriate Python exceptions
118+
- The `#[pymodule]` macro creates a Python module from the Rust module it encloses.
119+
- Each `#[pyfunction]` within the Rust module adds a Rust function to Python the `#[pymodule]`.
120+
- Each Rust error type must be handled and mapped to the appropriate Python exceptions.
120121

121122
## Step 2: Building and Packaging
122123

123-
[Maturin](https://github.com/PyO3/maturin) handles compiling the Rust code and packaging it as a Python wheel. Two configuration files control this process:
124+
[Maturin](https://github.com/PyO3/maturin) handles compiling the Rust code and packaging it as a Python wheel. Two configuration files control this process:
124125

125126
**Cargo.toml**
126127
```toml
@@ -157,7 +158,6 @@ features = ["pyo3/extension-module"]
157158
Building is as simple as:
158159

159160
```bash
160-
161161
maturin develop
162162
```
163163

@@ -183,7 +183,7 @@ def test_pngme_encode():
183183

184184
## Step 4: Handling Errors
185185

186-
PyO3 lets you map Rust errors to Python exceptions, so Python users get idiomatic error messages:
186+
PyO3 lets you map Rust errors to Python exceptions, so Python users get idiomatic error messages as shown below:
187187

188188
```python
189189
import pytest

0 commit comments

Comments
 (0)