pyo3  by PyO3

Rust bindings for Python, enabling native extension modules

created 8 years ago
14,068 stars

Top 3.6% 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

1 day ago

Responsiveness

1 day

Pull Requests (30d)
52
Issues (30d)
28
Star History
584 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Shawn Wang Shawn Wang(Editor of Latent Space), and
8 more.

llm by rustformers

0%
6k
Rust ecosystem for LLM Rust inference (unmaintained)
created 2 years ago
updated 1 year ago
Feedback? Help us improve.