explaingit

pyo3/pyo3

Analysis updated 2026-06-24

15,671RustAudience · developerComplexity · 3/5Setup · moderate

TLDR

PyO3 lets you write fast Rust code and call it from Python as if it were a normal Python library, or embed Python inside a Rust program, combining Python's ease of use with Rust's speed.

Mindmap

mindmap
  root((PyO3))
    What It Does
      Rust to Python bindings
      Python in Rust apps
      Native Python modules
    How It Works
      Rust attributes
      maturin build tool
      pip distribution
    Use Cases
      Speed up Python code
      High-perf libraries
      Embed Python in Rust
    Audience
      Python devs
      Rust devs
      Library authors
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Rewrite a slow Python function in Rust and call it from Python with a normal import, eliminating a performance bottleneck without changing the rest of your Python code.

USE CASE 2

Build and publish a high-performance native Python package using maturin so users can install it via pip.

USE CASE 3

Embed a Python interpreter inside a Rust application to call Python libraries like numpy from Rust code.

What is it built with?

RustPython

How does it compare?

pyo3/pyo3louis-e/arnisiii-hq/iii
Stars15,67115,69815,623
LanguageRustRustRust
Setup difficultymoderateeasymoderate
Complexity3/52/54/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires Rust toolchain and the maturin build tool installed, first compile can take several minutes.

In plain English

PyO3 is a library that connects two programming languages, Rust and Python, letting you use them together in the same project. It works in two directions: you can write code in Rust and call it from Python (making Python faster for performance-critical parts), or you can run Python code from inside a Rust program (embedding the Python interpreter). Rust is a systems programming language known for being very fast and memory-safe, while Python is popular for its ease of use. PyO3 lets you get the best of both: write the fast or complex parts in Rust, and expose them as if they were ordinary Python functions that any Python user can call. This is how many high-performance Python libraries are built under the hood. The code example in the README shows how to write a Rust function, annotate it with a simple attribute (#[pyfunction]), and then call it from Python with a normal import statement, the compiled Rust code becomes a native Python module. Going the other direction, you can embed a Python interpreter inside a Rust application and call Python libraries from Rust code. The companion tool maturin handles building and publishing these mixed Rust-Python packages with minimal configuration, you run a few commands and get a Python package you can distribute via pip (Python's package manager). You would use PyO3 if you have a Python project with a performance bottleneck that you want to rewrite in Rust, or if you are building a Rust application that needs to use Python libraries. The full README is longer than what was provided.

Copy-paste prompts

Prompt 1
Using PyO3 and maturin, write a Rust function that takes a Python list of integers and returns their sum, compiled as a native Python module I can import with `import my_module`.
Prompt 2
I have a slow Python function that processes 1 million items. Show me how to rewrite it in Rust with PyO3 attributes and expose it back to Python with the same calling signature.
Prompt 3
Walk me through the maturin commands to build and publish a PyO3 Rust extension as a pip-installable package on PyPI.
Prompt 4
Show me how to call a Python function from inside Rust code using PyO3's `Python::with_gil` so I can use a Python library inside a Rust binary.
Prompt 5
What Rust types does PyO3 automatically convert to and from Python types, and how do I handle a type that isn't automatically converted?

Frequently asked questions

What is pyo3?

PyO3 lets you write fast Rust code and call it from Python as if it were a normal Python library, or embed Python inside a Rust program, combining Python's ease of use with Rust's speed.

What language is pyo3 written in?

Mainly Rust. The stack also includes Rust, Python.

How hard is pyo3 to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is pyo3 for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.