$ pyo3
v0.28.0Bindings to Python interpreter
Latest Update Summary
Crate
Name: pyo3 New version: 0.27.0 Release date: 2025-10-19T11:17:23Z
Crate readme
Short description Rust bindings for Python, including tools for creating native Python extension modules.
Long description
PyO3 enables the creation of native Python modules using Rust, allowing Rust code to run inside Python applications and vice versa. It supports Python versions CPython 3.7+, PyPy 7.3+, and GraalPy 24.2+. The crate requires Rust 1.74 or higher and can integrate with tools like maturin and setuptools-rust for packaging.
Features • Supports CPython 3.7 or greater, PyPy 7.3+, GraalPy 24.2 or greater • Requires Rust 1.74 or greater • Integration with maturin for building Python packages • Uses pyo3 as a dependency for creating Python modules
Code Examples Using maturin to initialize a Python module
[package]
name = "string_sum"
version = "0.1.0"
edition = "2021"
[lib]
name = "string_sum"
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.27.0", features = ["extension-module"] }
Embedding Python in Rust
fn main() -> PyResult<()> {
Python::attach(|py| {
let sys = py.import("sys")?;
let version: String = sys.getattr("version")?.extract()?;
let locals = [("os", py.import("os")?)].into_py_dict(py)?;
let code = c_str!("os.getenv('USER') or os.getenv('USERNAME') or 'Unknown'");
let user: String = py.eval(code, None, Some(&locals))?.extract()?;
println!("Hello {}, I'm Python {}", user, version);
Ok(())
})
}
Links • https://pyo3.rs • https://docs.rs/pyo3/ • https://github.com/PyO3/pyo3 • https://pyo3.rs/v0.27.0/migration.html https://docs.rs/crate/pyo3/ https://api.github.com/repos/PyO3/pyo3/releases/255595618
Release info
Release version: 0.27.0
Release description
This release is notable as it is the first PyO3 release tested against the final Python 3.14.0 version, resulting in no significant changes in support compared to version 0.26, which was tested against the release candidates. However, support has been dropped for PyPy 3.9 and 3.10, both of which are no longer supported upstream. The FromPyObject trait has undergone a rework, aligning it with the IntoPyObject trait that was introduced in PyO3 0.23, creating a more performant and flexible implementation, with no anticipated changes moving forward. The .downcast() functions are deprecated in favor of the new .cast() functions, improving API usability and error messages for failed conversions. Additionally, changes have been made to operations on the PyCapsule type addressing issues with return value lifetimes, promoting the checking of capsule names to protect the validity of data casting through the capsule API. The release also includes several incremental improvements, bug fixes, and minor features, and users are advised to refer to the migration guide for detailed upgrade instructions.
Code Examples
Minor update: 0.27.2 → 0.28.0
$ DOWNLOADS TREND
$ VERSION HISTORY
$ LINKS
$ INSTALL
cargo add pyo3Or add to Cargo.toml: pyo3 = "0.28.0"