# PyO3/pyo3

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/pyo3-pyo3).**

15,344 stars · 941 forks · Rust · apache-2.0

## Links

- GitHub: https://github.com/PyO3/pyo3
- Homepage: https://pyo3.rs
- awesome-repositories: https://awesome-repositories.com/repository/pyo3-pyo3.md

## Topics

`binding` `ffi` `python` `python-c-api` `rust`

## Description

This project provides a framework for binding Rust and Python, enabling the creation of native extension modules and the embedding of the Python interpreter within host applications. It functions as a cross-language interoperability library that facilitates the execution of scripts, the definition of classes, and the sharing of data structures across the boundary of the two runtimes.

The framework distinguishes itself through the use of procedural macros to automate the generation of boilerplate code, simplifying the process of exposing native functions and data types. It employs type-level markers to manage the global interpreter lock and reference-counted containers to handle object lifetimes, ensuring thread safety and memory integrity during cross-language execution. An integrated exception translation layer further ensures that errors are mapped consistently between environments.

The toolset covers a broad range of development needs, including the compilation of native binary extensions, the generation of type stubs for static analysis, and the configuration of build environments to support multiple interpreter versions. It also provides capabilities for bridging logging frameworks and automating the recompilation of modules during development.

The project is distributed as a library that integrates with standard build tools to produce installable binary files.

## Tags

### Programming Languages & Runtimes

- [Foreign Function Interfaces](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/foreign-function-interfaces.md) — Provides a system for mapping data types, managing lifetimes, and translating exceptions between language environments.
- [Python Bindings](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/interoperability/python-bindings.md) — Provides a comprehensive framework for binding Rust and Python, enabling native extension development and interpreter embedding.
- [CommonJS Interop](https://awesome-repositories.com/f/programming-languages-runtimes/language-ecosystems-tooling/module-management/module-resolution/module-resolvers/commonjs-interop.md) — Acts as a bridge for calling functions, defining classes, and sharing data structures across runtimes.
- [Scripting Runtimes](https://awesome-repositories.com/f/programming-languages-runtimes/scripting-runtimes.md) — Integrates a language interpreter directly into host applications to enable standalone script execution. ([source](https://pyo3.rs/latest/building-and-distribution.html))
- [Language Interoperability](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability.md) — Maps complex data structures and types between languages to ensure safe and efficient communication.
- [Global Interpreter Locks](https://awesome-repositories.com/f/programming-languages-runtimes/compiler-interpreter-internals/interpreter-internals/global-interpreter-locks.md) — Manages thread safety and runtime state access across language boundaries using type-level markers.
- [Procedural Macros](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/metaprogramming/procedural-macros.md) — Uses compiler-level annotations to automatically generate boilerplate code for native language bindings.
- [Native Class Wrappers](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/interoperability/javascript-to-native-bridges/native-class-wrappers.md) — Exposes internal data structures as native classes for instantiation and method invocation from scripts. ([source](https://pyo3.rs/class.html))
- [Native Code Exporters](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/interoperability/javascript-to-native-bridges/native-structure-mappers/native-code-exporters.md) — Maps native functions and data structures to compatible interfaces for execution as native modules. ([source](https://pyo3.rs/main/doc))
- [Foreign Function Invocations](https://awesome-repositories.com/f/programming-languages-runtimes/programming-language-varieties/programming-languages/dynamic-scripting-languages/python/foreign-function-invocations.md) — Executes foreign functions and accesses objects by managing cross-language memory references. ([source](https://pyo3.rs/v0.29.0/print))
- [Lifetime Tracking Tokens](https://awesome-repositories.com/f/programming-languages-runtimes/programming-language-varieties/programming-languages/language-specific-resources/language-tutorials/c-c-tutorials/object-management/object-lifetime-management/lifetime-tracking-tokens.md) — Uses type-level tokens to track the global interpreter lock and ensure safe object access. ([source](https://pyo3.rs/main/doc))
- [Native Class Mappings](https://awesome-repositories.com/f/programming-languages-runtimes/class-creation-customization/native-class-mappings.md) — Maps custom data structures to classes to define methods and properties that interact with the host environment. ([source](https://pyo3.rs/v0.29.0/print))
- [Interpreter Internals](https://awesome-repositories.com/f/programming-languages-runtimes/compiler-interpreter-internals/interpreter-internals.md) — Initializes and manages the lifecycle of a language runtime within a host application. ([source](https://pyo3.rs))
- [Module Loaders](https://awesome-repositories.com/f/programming-languages-runtimes/language-ecosystems-tooling/module-management/module-loaders.md) — Loads external modules into the host environment to access their functionality directly. ([source](https://pyo3.rs/python-from-rust.html))
- [Module Preinitializers](https://awesome-repositories.com/f/programming-languages-runtimes/language-ecosystems-tooling/module-management/module-loaders/module-preinitializers.md) — Registers custom modules in an internal table to make them available for import within the runtime. ([source](https://pyo3.rs/latest/building-and-distribution.html))

### Development Tools & Productivity

- [Extension Compilers](https://awesome-repositories.com/f/development-tools-productivity/extension-compilers.md) — Compiles high-level source code into native binary extension modules for seamless integration with the Python interpreter.
- [Python Scripting Environments](https://awesome-repositories.com/f/development-tools-productivity/python-development-tools/script-execution-engines/python-scripting-environments.md) — Integrates the interpreter directly into host applications to enable dynamic script execution.
- [Python Development Tools](https://awesome-repositories.com/f/development-tools-productivity/python-development-tools.md) — Builds high-performance native modules to accelerate computationally intensive tasks.
- [Scripting Hosts](https://awesome-repositories.com/f/development-tools-productivity/scripting-hosts.md) — Executes scripts and manages objects directly within the host application to integrate external logic. ([source](https://pyo3.rs/building-and-distribution/multiple-python-versions.html))
- [Native Binary Toolchains](https://awesome-repositories.com/f/development-tools-productivity/build-tooling/build-orchestration-logic/build-orchestration-configuration/build-automation-systems/build-systems/binary-compilation-toolchains/native-binary-toolchains.md) — Compiles source code into shared library objects compatible with the host language runtime.
- [Script Execution Engines](https://awesome-repositories.com/f/development-tools-productivity/python-development-tools/script-execution-engines.md) — Executes arbitrary scripts and functions from within a host application to leverage external logic. ([source](https://pyo3.rs/python-from-rust/calling-existing-code.html))
- [Cross-Compilation Toolchains](https://awesome-repositories.com/f/development-tools-productivity/cross-compilation-toolchains.md) — Configures build environments to target multiple operating systems and hardware architectures. ([source](https://pyo3.rs/latest/building-and-distribution.html))
- [Translation Layers](https://awesome-repositories.com/f/development-tools-productivity/modular-architecture/translation-layers.md) — Provides an integrated layer that translates and maps errors between native and foreign language environments.
- [Type Definition Generators](https://awesome-repositories.com/f/development-tools-productivity/type-definition-generators.md) — Generates type stubs from native code to enable static analysis and IDE autocompletion in external projects. ([source](https://pyo3.rs/v0.29.0/print))

### Mobile Development

- [Module Development](https://awesome-repositories.com/f/mobile-development/native-modules-bridges/module-development.md) — Exposes performance-critical native logic as importable modules for use in standard scripts. ([source](https://pyo3.rs))

### DevOps & Infrastructure

- [Native Build Orchestrators](https://awesome-repositories.com/f/devops-infrastructure/cicd-pipeline-automation/core-build-engines/build-tooling/native-build-orchestrators.md) — Compiles source code into native modules and packages them as installable binary files. ([source](https://pyo3.rs/latest/building-and-distribution.html))

### Operating Systems & Systems Programming

- [Native System Extensions](https://awesome-repositories.com/f/operating-systems-systems-programming/platform-development-integration/native-system-extensions.md) — Creates native extension modules from compiled code to allow seamless integration with external scripts. ([source](https://pyo3.rs/main))
- [Cross-Language Memory Managers](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/memory-safety-and-semantics/cross-language-memory-managers.md) — Uses reference-counted containers to manage object lifetimes and prevent memory leaks during cross-language execution.

### Data & Databases

- [Type Mapping Converters](https://awesome-repositories.com/f/data-databases/type-mapping-utilities/type-mapping-converters.md) — Automatically maps complex data structures and primitive values between language runtimes. ([source](https://pyo3.rs/conversions/tables.html))

### Software Engineering & Architecture

- [Exception Hierarchies](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/exception-logic-structures/exception-hierarchies.md) — Translates and propagates errors between language environments using unified exception hierarchies. ([source](https://pyo3.rs/main/doc))
- [Exception Mappers](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/exception-logic-structures/exception-mappers.md) — Translates native exceptions into corresponding types to maintain consistent error handling across environments. ([source](https://pyo3.rs/exception.html))
- [Type Definition Generators](https://awesome-repositories.com/f/software-engineering-architecture/type-definition-generators.md) — Generates interface definition files from compiled modules to support static analysis and autocompletion. ([source](https://pyo3.rs/type-stub.html))
