python-bindings

Create Python bindings for Rust code using PyO3 and Maturin.

1|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/agentglass/claude-trace --skill python-bindings-agentglass
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-bindings
Source: https://github.com/agentglass/claude-trace/tree/main/.claude-plugin/skills/python-bindings
Command: npx skills add https://github.com/agentglass/claude-trace --skill python-bindings-agentglass

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides expert context and patterns for building robust Python bindings for Rust code using PyO3 and Maturin, ensuring efficient, safe, and maintainable extensions.

Core Features & Use Cases

  • PyO3 Best Practices: Demonstrates correct usage of PyO3 0.26 features like gil_used = false, Bound<'_, T>, and class definition patterns.
  • Maturin Workflow: Outlines essential commands for development, building wheels, and publishing Python packages from Rust.
  • Error Handling & Type Stubs: Details how to convert Rust errors to Python exceptions and generate accurate type stubs (.pyi) for improved developer experience.
  • Use Case: A developer needs to create a high-performance Python library by wrapping existing Rust code. This Skill guides them through the entire process, from Rust implementation to a distributable Python package.

Quick Start

Use the python-bindings skill to build a Python wheel for your Rust project using maturin.

Frequently Asked Questions about python-bindings

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create Python bindings for Rust code using PyO3?

To create Python bindings for Rust code using PyO3, you define module entry points and classes in Rust, then use Maturin to build and package the compiled extension modules into distributable Python wheels.

What is the best way to manage the GIL when writing Rust extensions for Python?

Managing the GIL when writing Rust extensions for Python involves using PyO3's `gil_used = false` feature and `Bound<'_, T>` patterns to safely handle or release the Global Interpreter Lock during execution.

How do I convert Rust errors to Python exceptions in extension modules?

You convert Rust errors to Python exceptions in extension modules by implementing PyO3's error conversion patterns, allowing your Rust library's native error types to map seamlessly into appropriate Python exceptions.

Does Maturin support generating type stubs for Rust extensions?

Yes, Maturin supports generating type stubs for Rust extensions. It provides essential commands to automatically generate `.pyi` files, ensuring an improved developer experience with accurate type hints for your Python public API layer.

Can I implement a Python context manager entirely in Rust?

Yes, you can implement a Python context manager entirely in Rust. The PyO3 framework provides specific class definition patterns that allow you to map Rust structs and methods directly to Python context manager protocols.

What is the workflow for building and publishing a Python package from Rust with Maturin?

The workflow for building and publishing a Python package from Rust with Maturin involves using specific Maturin commands for local development, compiling Rust into extension modules, building wheels, and publishing the final package.