"PyO3: Building Python Extension Modules in Native Rust with Performanc" by Price D. Johnson and Douglas D. Hodson 10.1007/978-3-031-85902-1_4">
 

PyO3: Building Python Extension Modules in Native Rust with Performance and Safety in Mind

Document Type

Conference Proceeding

Publication Date

4-23-2025

Abstract

Python and Rust are both powerful programming languages, each offering unique benefits depending on individual use cases. Rust is a lower-level programming language built with speed and safety as integral features. Python, known for being more user-friendly, has an extensive library with over 350,000 publicly available packages [1]. Writing Rust software can be a daunting and meticulous task, as its syntax and strict compiler demand careful attention to detail. This meticulousness often pays off in the form of highly performant and safe code. Conversely, Python has a straightforward syntax that allows programmers a wide range of flexibility in writing code. However, Python’s performance can be limiting, often requiring the use of native C or C++ libraries for computationally heavy tasks. This paper introduces the PyO3 crate, which enables programmers to seamlessly integrate native Python modules and Rust code within the same project, allowing for the development of high-performance Python extension modules using Rust. Additionally, it provides insights into interfacing between the two code bases using various PyO3 tools. This approach enables programmers to benefit from combining both languages while maintaining good coding standards by keeping them separate and interfacing between them. PyO3 opens the door for Rust to replace C and C++ in Python modules, offering a safer alternative while not compromising efficiency.

Comments

This conference paper is published by Springer and is available by purchase or subscription through the DOI link below.

Source Publication

Scientific Computing and Bioinformatics and Computational Biology (CSCE 2024). Communications in Computer and Information Science (CCIS), Volume 2258

This document is currently not available here.

Share

COinS