pyo3  by PyO3

Rust bindings for Python, enabling native extension modules

Created 8 years ago
14,400 stars

Top 3.4% on SourcePulse

GitHubView on GitHub
Project Summary

PyO3 provides robust Rust bindings for the Python interpreter, enabling developers to write high-performance Python extensions in Rust or embed Python within Rust applications. It targets Python developers seeking to optimize critical code paths and Rust developers looking to leverage Python's ecosystem.

How It Works

PyO3 facilitates seamless interaction between Rust and Python by generating Python extension modules or embedding Python interpreters. It uses Rust's type system and memory safety to create efficient, reliable Python components. The #[pyfunction] and #[pymodule] attributes simplify the creation of Python-callable functions and modules, while Python::with_gil manages the Global Interpreter Lock for safe interop.

Quick Start & Requirements

  • Install: Use pip install maturin and then maturin init --bindings pyo3 to scaffold a new project. Build and install with maturin develop.
  • Requirements: Rust 1.63+, Python 3.7+ (CPython), PyPy 7.3+, or GraalPy 24.0+. Ubuntu users may need sudo apt install python3-dev.
  • Resources: Project setup involves standard Rust/Python tooling.
  • Docs: User Guide, API Docs

Highlighted Details

  • Enables writing Python extension modules in Rust with minimal boilerplate.
  • Supports embedding Python interpreters within Rust applications.
  • Integrates with tools like maturin for streamlined building and publishing.
  • Powers numerous high-performance Python libraries including Polars, Pydantic-core, and Tokenizers.

Maintenance & Community

  • Actively maintained by David Hewitt and Messense, with contributions from a large community.
  • Community support available via Discord.
  • Sponsorships are welcomed for maintainers.

Licensing & Compatibility

  • Licensed under Apache-2.0 or MIT license, allowing for commercial use and integration into closed-source projects.
  • Compatible with CPython, PyPy, and GraalPy.

Limitations & Caveats

The project requires a Rust toolchain and specific Python versions. Embedding Python requires the Python shared library to be installed on the system. Some advanced use cases or linker issues might require consulting the FAQ.

Health Check
Last Commit

2 days ago

Responsiveness

1 day

Pull Requests (30d)
88
Issues (30d)
32
Star History
206 stars in the last 30 days

Explore Similar Projects

Starred by George Hotz George Hotz(Author of tinygrad; Founder of the tiny corp, comma.ai), Patrick von Platen Patrick von Platen(Author of Hugging Face Diffusers; Research Engineer at Mistral), and
6 more.

jaxtyping by patrick-kidger

0.7%
2k
Typing library for array shapes/dtypes
Created 3 years ago
Updated 4 months ago
Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Luis Capelo Luis Capelo(Cofounder of Lightning AI), and
12 more.

llm by rustformers

0.1%
6k
Rust ecosystem for LLM Rust inference (unmaintained)
Created 2 years ago
Updated 1 year ago
Feedback? Help us improve.