pyo3-bindings

Solid

PyO3 conventions for exposing a Rust core to Python: pyclass/pymethods, PyErr/PyResult error mapping, GIL release, properties, maturin builds, and pytest. Load when generating or reviewing PyO3 Python bindings for a Rust library.

Data & Documents 137 stars 13 forks Updated today MIT

Install

View on GitHub

Quality Score: 84/100

Stars 20%
71
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
48
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

- Use `#[pyclass]` and `#[pymethods]` for Python-visible types. Use `#[new]` for constructors. - Map Rust `Result<T, E>` to Python exceptions via `PyErr`. Use `PyResult<T>` as return type. - Use `pyo3::types` for conversions. Prefer `&str` over `String` in parameters, return `String`. - Prefer `Bound<'py, T>` over `Py<T>` for ergonomic, lifetime-checked references (PyO3 0.22+). - Release the GIL with `py.allow_threads()` for CPU-intensive Rust code. Never hold GIL during I/O. - Use `#[getter]` and `#[setter]` for properties. Implement `__repr__` and `__str__` for debugging. - Build with `maturin develop` for local testing, `maturin build --release` for distribution. - Test bindings from Python using `pytest`. Test both success and error paths. - Keep Python wrappers thin — business logic lives in Rust, Python provides ergonomic API. - Anti-patterns: `.unwrap()` in pyclass methods, blocking GIL for long operations, leaking Python objects.

Details

Author
Goldziher
Repository
Goldziher/ai-rulez
Created
1 years ago
Last Updated
today
Language
Go
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

API & Backend Listed

rust-pyo3-project-standard

Enforce a strict project standard for Rust-backed Python packages built with PyO3 and Maturin, including abi3 compatibility, Python wrapper typing, wheel packaging, cross-platform CI, API/documentation parity, and release gates. Use when creating, auditing, restructuring, testing, or releasing a repository containing Cargo.toml plus pyproject.toml with maturin/PyO3; when deciding whether Python-project-standard rules such as src layout, Python 3.13, beartype, or pydantic apply; or when a Rust extension exposes Python APIs.

1 Updated 2 weeks ago
VoldemortGin
Data & Documents Solid

rust-polyglot-conventions

Rust conventions for a core that backs multiple language bindings: stable-edition tooling, typed Result errors with no panics in library paths, rustdoc with error docs, isolated unsafe, Send futures, FFI-friendly DTOs, and single-source version syncing. Load when writing or reviewing a Rust core exposed through polyglot bindings.

137 Updated today
Goldziher
AI & Automation Listed

port-from-python

Port Python into Rust — construct mapping, the semantic traps (integer width, floor division, str versus bytes, exceptions to Result), and the seam, which is a process boundary for a standalone replacement and PyO3 when Python keeps calling the code. Use when porting, rewriting, or migrating Python, CPython, Django, Flask, FastAPI, NumPy, or a Python CLI into Rust, when replacing a Python tool with a Rust binary or a hot Python module with a native extension, or when the user asks how a Python construct translates to Rust.

1 Updated 4 days ago
rewrite-rs