Two CPython developers have proposed introducing the Rust programming language into Python’s codebase. Emma Smith and her colleague published a preliminary Python enhancement proposal (Pre-PEP) outlining the rationale behind this move. For now, Rust is intended only for optional extension modules, but it may eventually become a required dependency.
The primary motivation for adopting Rust is improved memory safety. The language prevents entire classes of errors at compile time — out-of-bounds access, use-after-free, and data races in multithreaded code. This is especially critical for free-threaded Python, where thread safety becomes paramount. The RustBelt project has even formally proven Rust’s safety guarantees for code that avoids unsafe constructs.
CPython routinely encounters bugs stemming from incorrect memory handling. The authors argue that Rust would dramatically reduce such issues. Even if some parts must remain unsafe due to interaction with the C API, core module logic could be implemented in safe Rust.
Rust is already widely adopted across major C and C++ projects. The Linux kernel, Android, Firefox, and many other systems are incorporating it to enhance reliability. Google has reported positive results from using Rust in Android. Notably, between 25% and 33% of new Python extensions are already written in Rust — integrating the language directly into CPython could further accelerate this trend.
Beyond safety, Rust offers high-performance data structures in its standard library — vectors, hash maps, mutexes — all implemented with zero-cost abstractions and excellent documentation. Rust’s macro system surpasses that of C: declarative macros are hygienic and avoid accidental variable capture, while procedural macros enable powerful code transformations. The PyO3 library heavily relies on procedural macros to simplify interaction with Python’s API.
The developers have already produced a prototype containing an alternative _base64 module, demonstrating performance gains with Rust. Integration will require a new crate, cpython-sys, with FFI definitions of the C API. Bindings would be generated with bindgen, Rust’s official tool — the same used in Linux and Android projects. Cargo can vendor dependencies natively, so builds won’t require downloading packages.
Rust supports every platform listed in PEP 11, and more. All tier-1 Python platforms correspond to tier-1 or tier-2 Rust targets with full developer tooling. Cross-compilation is straightforward: install the target and specify the linker.
The authors rejected the idea of using PyO3 internally within CPython, as it would introduce an unnecessary abstraction layer and slow development — every new API would require parallel updates in PyO3 before CPython could use it. With bindgen, new APIs become available automatically.
One complication is circular dependency: the Rust compiler uses Python during bootstrap. But solutions exist. One can build an older Python, then Rust, and finally the new CPython. Rust’s bootstrap scripts even remain compatible with Python 2, so the obstacle is manageable. Alternatives include using PyPy or removing Python from Rust’s bootstrap entirely.
Training resources are planned for current CPython contributors. The Rust Book provides a comprehensive introduction; there is also Rust for C++ programmers and official tutorials. The project intends to establish a Rust expert team and add a tutorial to the developer guide. Handling Python function arguments may require adapting Argument Clinic or implementing a procedural macro in Rust.