https://github.com/ivaniscoding/hands-on-pyo3
Extending Python with Rust: a hands-on introduction to PyO3
https://github.com/ivaniscoding/hands-on-pyo3
Last synced: 3 months ago
JSON representation
Extending Python with Rust: a hands-on introduction to PyO3
- Host: GitHub
- URL: https://github.com/ivaniscoding/hands-on-pyo3
- Owner: IvanIsCoding
- License: mit
- Created: 2025-09-21T23:29:11.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-10-08T03:39:40.000Z (3 months ago)
- Last Synced: 2025-10-08T05:36:50.511Z (3 months ago)
- Language: Jupyter Notebook
- Size: 1.1 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Extending Python with Rust: a hands-on introduction to PyO3
This is an example project using [PyO3](https://github.com/PyO3/pyo3). The goal
of this project is to provide a practical example.
To see it in action: [](https://colab.research.google.com/github/IvanIsCoding/hands-on-pyo3/blob/main/00_Example_Usage.ipynb)
## Structure
```
.
├── 00_Example_Usage.ipynb # Installs the extension from source and tests it
├── Cargo.toml # Defines the Rust manifest: crate name, deps, and more.
├── pyproject.toml # Configuration for Python: defines the build system and deps, and more.
├── Cargo.lock # Lockfile generated by Cargo. This is auto-generated.
├── src/ # Rust implementation using PyO3 and jxl-oxide
├── slides # Slides source in markdown + rendered PDF
├── .cargo # Config files to make this project compile for macOS
└── README.md # This file!
```
## Purpose
This example extension lets users load [JPEG XL](https://en.wikipedia.org/wiki/JPEG_XL)
images into Python as NumPy arrays and [Pillow Images](https://pillow.readthedocs.io/en/stable/reference/Image.html).
We leverage [jxl-oxide](https://docs.rs/jxl-oxide/0.11.4/jxl_oxide/) to read the JPEG XL images. This demo code wraps the Rust crate and makes it available for Python users.
## Usage
To install from source, firstly ensure you have a Rust compiler available.
Then, simply run:
```bash
pip install .
```
Once that is done, the extension module should be available in Python:
```python
import jxl_demo
```
The `jxl_demo` module has two functions: `decode_jxl` and `decode_jxl_as_array`.