Skip to main content
LeoNex News

Rust in CPython? Discussion at the Python Language Summit

Illustration: Rust in CPython? Discussion at the Python Language Summit
In this article

David Hewitt, representing the Rust for CPython project team, returned to the Python Language Summit to ask Python's core developers what they want from Rust. He presented a phased roadmap, success criteria and a proposal to start with an optional Rust backend for the zlib module. The long-term goal is to make Rust a stable part of CPython, accompanied by quite a few concerns from the community.

According to David, the number of GitHub issues labeled type-crash has been rising steadily over time. He argued that CPython has bet on large, complex features such as the new parser, the JIT (just-in-time compilation) and free-threading (running threads in parallel without a global lock), and that this may be why the number of crash reports is growing. Rust is seen as one possible way to address this.

  • In Android, Jeff Vander Stoep described Rust as "move fast and fix things"; Android's experience since adopting Rust is fewer revision cycles for patches of the same size.

  • Rust and Python already work together in the package ecosystem thanks to PyO3 and Maturin.

  • Many tech companies choose Rust as a strategic investment, not just because it is a flashy new tool.

  • The project team already has experience bringing Rust into existing codebases such as Android and the Linux kernel.

Concerns and mitigations

David acknowledged that bringing Rust into CPython is not entirely smooth. Three main groups of concerns were raised, along with the corresponding approaches to handling them.

  1. Platform support: last year this was a major concern because CPython officially supports 20 architectures and platforms at Tier 1, 2 or 3. David said Rust's platform coverage has expanded and is becoming less of a worry. The proposal is to ask Python distributors to try the optional Rust support in Python 3.16 (October 2027) and report platform-specific bugs upstream so they can be dealt with in time around the Python 3.17 (October 2028) milestone.

  2. Social factors: knowledge of Rust is not widespread among core developers. The mitigation is to target small parts of CPython and proceed step by step, since 1 million lines of C code cannot be converted all at once.

  3. Bugs and security: using Rust does not mean the converted code will be free of bugs or vulnerabilities. Rust eliminates some common classes of bugs, but code can still be incorrect. The team proposes using property-based testing, fuzzing and careful engineering practices during the conversion.

Roadmap and the first module: zlib

A PEP defining the success criteria for Rust is expected at the end of 2026. According to the roadmap, the first Rust code ships with Python 3.16 and is entirely optional, with the old C code kept as a fallback. Python 3.18 in 2029 at the earliest is when Rust would become a requirement for building CPython, meaning at least three more years.

  1. Summer 2026: build system, CI and a proof-of-concept Rust API.

  2. End of 2026: a PEP defining the success criteria.

  3. Python 3.16 (October 2027): an optional Rust backend for the zlib module and a private Rust API.

  4. Python 3.17 (October 2028): resolve platform issues and extend Rust to io, json, xml, memoryview and the parser.

  5. A later Python version (October 2029+): Rust becomes mandatory for builds and a public Rust API is released.

The team chose zlib as the first module because it wanted a significant improvement with a small scope. The implementation uses zlib-rs, which is described as well tested, used by Firefox, uv and Cargo, and faster than zlib and zlib-ng on many platforms. The module also forces the use of an external Cargo package, so this part of the build process will have to be designed and trialed. Because the zlib compression algorithm is widely used in Python packaging, almost every pip install command on Python 3.16 would be faster if the proposal is accepted.

Sketch of the Rust API

plaintext
#[pyfunction(signature = (
 data,
 / ,
 wbits = MAX_WBITS ,
 bufsize = DEF_BUF_SIZE ,
 ))]
 fn decompress (
 py : Python <' _ >,
 data : Py < PyObject >,
 wbits : c_int,
 bufsize : isize
 ) -> PyResult < Py < PyBytes >, PyErrRaised > {

In the example, the buffer is allocated and freed automatically when it goes out of scope, instead of having to be cleaned up manually as when writing the same function in C.

Success criteria and discussion

For earlier major changes such as the JIT and free-threading, CPython set clear success criteria to justify the added complexity, and David argued this project needs the same. His suggestions:

  • The most important criterion: a majority of active core developers are willing to use the Rust API to implement functionality.

  • No significant slowdown on CPython's performance benchmarks.

  • Every tiered platform must be supported by Rust, and distributors' experience shows that adding Rust support is generally manageable.

David noted that the first criterion uses the word "open" rather than "familiar", and that he plans to survey core developers about how they have used Rust when contributing to CPython before deciding to take Rust out of the experimental stage.

In the discussion, Thomas Wouters advised against making concessions for people used to the old way and asked whether the Rust API should be designed from first principles. David replied that in some places it makes sense to take advantage of Rust's strengths, such as releasing resources when they go out of scope, but that some idiomatic Rust designs are not the best fit. Larry Hastings asked why not do a rewrite; David pointed out that RustPython already exists, is slower than CPython but could help guide API design. David also stated that CPython will be a two-language project for a considerable time, but said that claiming Rust will stay optional forever would be dishonest.

Pablo Galindo Salgado raised concerns about pulling dependencies from Cargo, which could be a showstopper because CPython vendors its dependencies and chooses them very carefully, and every time a vulnerability appears a new release is needed. David responded that the team will choose as few external dependencies as possible, zlib-rs being only one, that the Rust source code will be vendored so that building CPython does not require Cargo, and that it will not live inside the CPython source tree. Łukasz Langa agreed that dependencies should be kept separate, mentioning the cpython-source-deps repository, currently used only for binary installers.

Key points

More in Software Engineering

Illustration: Notable V8 changes from Node.js 26 to 27
SOFT-ENG Software Engineering

Notable V8 changes from Node.js 26 to 27

The Node.js 27 Alpha upgrades V8 to version 15.6, up from 14.6 in Node.js 26. The upgrade brings several new JavaScript language features, a number of behavior changes, performance improvements and memory adjustments. Some changes may break code that relies on the old behavior, so developers should…

3 min read

Illustration: Free-threaded Python (no GIL): the next phase
SOFT-ENG Software Engineering

Free-threaded Python (no GIL): the next phase

At the Python Language Summit, Tobias Wrigstad, Fridtjof Stoldt and Donghee Na returned to the topic of Python's post-free-threading era and the question of which high-level concurrency primitives the language should offer. The team proposes the Behavior-Oriented Concurrency (BOC) model…

4 min read

Email newsletter

Receive a selection of new LeoNex News articles by email.

We only use this address to send the newsletter.

Receive a selection of new LeoNex News articles by email. You will receive a confirmation email; the subscription only takes effect after you confirm. Every email includes an unsubscribe link. Read the privacy policy