Red Hot Cyber
Cybersecurity is about sharing. Recognize the risk, combat it, share your experiences, and encourage others to do better than you.
Cybersecurity is about sharing. Recognize the risk,
combat it, share your experiences, and encourage others
to do better than you.
UtiliaCS 320x100
Banner Desktop
Python to Rust: A More Secure Future for the Programming Language

Python to Rust: A More Secure Future for the Programming Language

19 November 2025 21:26

Two CPython developers have proposed adding the Rust programming language to the Python codebase . Emma Smith and a colleague have published a Preliminary Python Enhancement Proposal (Pre-PEP) justifying this step. Currently, Rust is only intended for writing optional extension modules, but it may become a required dependency in the future.

The main reason for adopting Rust is to improve memory safety . The language prevents entire classes of compile-time errors: out-of-bounds array accesses, accesses to freed memory, and data conflicts in multithreaded code.

This is especially relevant for Python, which uses free threads, where thread safety is paramount. The RustBelt project has even formally demonstrated the correctness of Rust’s safety guarantees for code free of unsafe constructs.

CPython regularly encounters bugs due to improper memory management. The authors of the proposal believe that Rust will radically reduce these problems. Even if some code remains unsafe due to interactions with the C API, the core logic of the modules will be written in Rust, a safe language.

Rust is already actively used by large C and C++ projects. The Linux kernel , Android , Firefox , and many other systems are adopting the language to improve reliability.

Google has already reported positive results from implementing Rust on Android. Interestingly, 25% to 33% of new Python extensions are written in Rust; integrating the language into CPython could further boost this trend.

In addition to security, Rust offers high-performance data structures from the standard library . Vectors, hash tables, and mutexes are all implemented with zero overhead and are well documented.

Rust’s macro system is superior to C macros : declarative macros are cleaner and don’t accidentally capture variables, while procedural macros allow for powerful code transformations . The PyO3 library makes extensive use of procedural macros to simplify using the Python API.

Developers have already created a prototype _base64 module that demonstrates the performance improvements achieved using Rust.

Integration will require a new cpython-sys crate with C FFI API definitions. Bindings are generated using bindgen , the official Rust tool also used in Linux and Android projects. Cargo can provide dependencies out of the box, so there’s no need to download packages during compilation.

Rust supports all platforms specified in PEP 11 and later . All Level 1 Python platforms correspond to Level 1 or Level 2 Rust platforms, with a full set of development tools. Cross-compilation is easy to set up: just set the desired target and specify the linker.

The authors abandoned the idea of using the existing PyO3 library within CPython. This would have created an additional layer of abstraction and slowed development: each new API would have been added to PyO3 first, then updated in CPython. With bindgen, new APIs are available automatically.

There’s a dependency problem: the Rust compiler uses Python for bootstrapping . But there are workarounds. You can compile an older version of Python, then Rust, then the new CPython . Rust’s bootstrapping scripts are even compatible with Python 2 , so the problem is solvable. Alternatives are to use PyPy or have Rust decouple from Python during the build process.

Training resources are available for current CPython developers. The Rust Book offers a comprehensive introduction to the language, as well as Rust for C++ Programmers and official training materials .

Plans are underway to create a Rust expert team and add a tutorial to the devguide . Working with function arguments may require adapting Argument Clinic or creating a procedural macro in Rust.

Follow us on Google News to receive daily updates on cybersecurity. Contact us if you would like to report news, insights or content for publication.

Cropped RHC 3d Transp2 1766828557 300x300
The editorial staff of Red Hot Cyber is composed of IT and cybersecurity professionals, supported by a network of qualified sources who also operate confidentially. The team works daily to analyze, verify, and publish news, insights, and reports on cybersecurity, technology, and digital threats, with a particular focus on the accuracy of information and the protection of sources. The information published is derived from direct research, field experience, and exclusive contributions from national and international operational contexts.