Rust Enters CPython: Python 3.16 Adds Optional Rust zlib Backend

Python 3.16 will introduce an optional Rust backend for the zlib module, marking the first Rust code in CPython, with a roadmap to make Rust mandatory by Python 3.18 in 2029, while addressing performance gains, dependency concerns, and success criteria for the Rust for CPython initiative.

21CTO
21CTO
21CTO
Rust Enters CPython: Python 3.16 Adds Optional Rust zlib Backend

Two Python core developers, Emma Smith and Kirill Podoprigora, are leading an effort to bring Rust into the standard CPython interpreter, starting with individual standard‑library modules.

Roadmap: Optional Rust in 3.16, Mandatory by 3.18

According to the published roadmap, Python 3.16 (scheduled for October 2027) will ship a Rust implementation of the zlib compression module as an optional backend. Users who build Python without Rust will continue to get the C implementation. However, from 2029 onward, Python 3.18 will require Rust.

The plan was presented by David Hewitt, maintainer of the PyO3 Rust bindings, at the Python Summit 2026. While Rust is already widely used for Python extensions via PyO3, this marks its first entry into CPython itself.

Why zlib? Performance and Build‑Process Validation

Hewitt chose zlib as the entry point because, despite its modest scope, it can deliver significant performance improvements and introduces an external Rust dependency — zlib-rs — allowing the team to test how the build system handles Cargo packages. zlib-rs is already used in Firefox and Cargo and is faster than the traditional zlib build on many platforms. Prototype benchmarks show a six‑fold decompression speedup on ARM‑based Macs, though CRC32 checksum computation runs nearly three times slower.

https://github.com/Rust-for-CPython/zlib-py

Next Steps: Internal Rust Interface and More Modules

Python 3.16 will include an internal Rust interface, and version 3.17 may add modules such as json and xml. Several Linux distributions plan to test the Rust‑enabled 3.16 builds and report platform‑specific issues.

Success Criteria and Dependency Concerns

The team has defined explicit success criteria for ending Rust’s experimental status, similar to those used for the JIT compiler and free‑threading efforts:

Most active core developers are willing to implement new features in Rust.

CPython benchmarks show no significant regressions.

Rust supports all officially supported platforms without imposing undue burden on developers.

Hewitt argues that describing Rust as permanently optional would be dishonest.

A Steering Council member raised a concern: the many Cargo packages could introduce security vulnerabilities that would force Python to issue new releases. Hewitt counters that the team aims to minimize dependencies and will ship source code separately so CPython can be built without Cargo.

Delayed Mandate and Upcoming PEP

Originally slated as a mandatory part of Python 3.16, the Rust requirement was postponed after objections including portability concerns. A formal proposal with success criteria will be submitted as a Python Enhancement Proposal (PEP) by late 2026, after which the Steering Council will make a final decision.

https://peps.python.org/pep-0826/

Per the release schedule, Python 3.16’s feature freeze occurs on 4 May 2027.

https://discuss.python.org/t/pre-pep-rust-for-cpython/104906
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Rustmemory safetyCPythonzlibPyO3Python 3.16PEP 826zlib-rs
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.