PyO3 / pyo3
Rust bindings for the Python interpreter
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing PyO3/pyo3 in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewPyO3 Rust bindings for Python, including tools for creating native Python extension modules. Running and interacting with Python code from a Rust binary is also supported. • User Guide: stable | main • API Documentation: stable | main Usage Requires Rust 1.83 or greater. PyO3 supports the following Python distributions: • CPython 3.7 or greater • PyPy 7.3 (Python 3.11+) • GraalPy 25.0 or greater (Python 3.12+) You can use PyO3 to write a native Python module in Rust, or to embed Python in a Rust binary. The following sections explain each of these in turn. Using Rust from Python PyO3 can be used to generate a native Python module. The easiest way to try this out for the first time is to use . is a tool for building and publishing Rust-based Python packages with minimal configuration. The following steps install , use it to generate and build a new Python package, and then launch Python to import and execute a function from the package. First, follow the commands below to create a new directory containing a new Python , and install into the virtualenv using Python's package manager, : Still inside this directory, now run . This will generate the new package source. When given the choice of bindings to use, select pyo3 bindings: The most important files generated by this command are and , which will look roughly like the following: ** ** ** ** Finally, run . This will build the package and install it into the Python virtualenv previously created and activated. The package is then ready to be used from : To make changes to the package, just edit the Rust source code and then re-run to recompile. To run this all as a single copy-and-paste, use the bash script below (replace in the first command with the desired package name): If you want to be able to run or use this project in a Cargo workspace and are running into linker issues, there are some workarounds in the FAQ. As well as with , it is possible to build using or manually. Both offer more flexibility than but require more configuration to get started. Using Python from Rust To embed Python into a Rust binary, you need to ensure that your Python installation contains a shared library. The following steps demonstrate how to ensure this (for Ubuntu), and then give some example code which runs an embedded Python interpreter. To install the Python shared library on Ubuntu: To install the Python shared library on RPM based distributions (e.g. Fedora, Red Hat, SuSE), install the package. Start a new project with and add to the like this: Example program displaying the value of and the current user name: The guide has a section with lots of examples about this topic. Tools and libraries • maturin _Build and publish crates with pyo3, rust-cpython or cffi bindings as well as rust binaries as python packages_ • setuptools-rust _Setuptools plugin for Rust support_. • pyo3-built _Simple macro to expose metadata obtained with the crate as a _ • rust-numpy _Rust binding of NumPy C-API_ • dict-derive _Derive FromPyObject to automatically transform Python dicts into Rust structs_ • pyo3-log _Bridge from Rust to Python logging_ • pythonize _Serde serializer for converting Rust objects to JSON-compatible Python objects_ • pyo3-async-runtimes _Utilities for interoperability with Python's Asyncio library and Rust's async runtimes._ • rustimport _Directly import Rust files or crates from Python, without manual compilation step. Provides pyo3 integration by default and generates pyo3 binding code automatically._ • pyo3-arrow _Lightweight Apache Arrow integration for pyo3._ • pyo3-bytes _Integration between and pyo3._ • pyo3-object_store _Integration between and ._ Examples • anise _A modern, high-performance toolkit for spacecraft mission design, notably used to help softly land Firefly Blue Ghost on the Moon on 02 Feb 2025._ • arro3 _A minimal Python library for Apache Arrow, connecting to the Rust arrow crate._ • arro3-compute _ _ • arro3-core _ _ • arro3-io _ _ • bed-reader _Read and write the PLINK BED format, simply and efficiently._ • Shows Rayon/ndarray::parallel (including capturing errors, controlling thread num), Python types to Rust generics, Github Actions • blake3-py _Python bindings for the BLAKE3 cryptographic hash function._ • Parallelized builds on GitHub Actions for MacOS, Linux, Windows, including free-threaded 3.13t wheels. • cellular_raza _A cellular agent-based simulation framework for building complex models from a clean slate._ • connector-x _Fastest library to load data from DB to DataFrames in Rust and Python._ • cryptography _Python cryptography library with some functionality in Rust._ • css-inline _CSS inlining for Python implemented in Rust._ • datafusion-python _A Python library that binds to Apache Arrow in-memory query engine DataFusion._ • deltalake-python _Native Delta Lake Python binding based on delta-rs with Pandas integration._ • fastbloom _A fast bloom filter | counting bloom filter implemented by Rust for Rust and Python!_ • fastuuid _Python bindings to Rust's UUID library._ • fast-paseto _High-performance PASETO (Platform-Agnostic Security Tokens) implementation with Python bindings._ • feos _Lightning fast thermodynamic modeling in Rust with fully developed Python interface._ • finalytics _Investment Analysis library in Rust | Python._ • forust _A lightweight gradient boosted decision tree library written in Rust._ • geo-index _A Rust crate and Python library for packed, immutable, zero-copy spatial indexes._ • granian _A Rust HTTP server for Python applications._ • haem _A Python library for working on Bioinformatics problems._ • hifitime _A high fidelity time management library for engineering and scientific applications where general relativity and time dilation matter._ • html2text-rs _Python library for converting HTML to markup or plain text._ • html-py-ever _Using html5ever through kuchiki to speed up html parsing and css-selecting._ • hudi-rs _The native Rust implementation for Apac…