Python or Rust comes down to where the code should execute and who manages memory, and for many applications the answer is both: the PyO3 user guide describes how to write a native Python module in Rust, so a Python application can keep its interface while a Rust component does the heavy work. Python’s own tutorial positions the language for scripting and rapid application development, while Rust’s ownership rules are checked by the compiler, and a program that breaks them will not compile. The published speed gaps between the two are wide and uneven, so the practical route is to measure the slow part of your program before deciding what, if anything, to rewrite.
Don't miss new tech stories on Google
Add Tech Insider once in the Google app and our stories appear in your news suggestions.
Rust’s compiler enforces ownership; Python’s tutorial points to scripting
The Python tutorial says the language’s dynamic typing and interpreted nature make it “an ideal language for scripting and rapid application development” on most platforms. It adds that the interpreter and the extensive standard library are freely available in source or binary form for all major platforms. In the default CPython build, according to the free-threading HOWTO, an object is normally deallocated when its reference count reaches zero.
Rust takes a different route. The Rust Book says memory is managed through a system of ownership “with a set of rules that the compiler checks”. Each value has an owner, only one owner can exist at a time, and the value is dropped when the owner goes out of scope. Moving a value invalidates the old binding, which is how Rust avoids freeing the same allocation twice:
let first = String::from("hello");
let second = first;
// `first` is no longer valid after the move; the compiler rejects any later use
The cost is learning time. The Rust Book itself says that because ownership is a new concept for many programmers, “it does take some time to get used to”. In practice the ownership checks arrive while you write the code, which is a poor trade for a one-off script and a good one for a component that must manage its own resources.
Five Benchmarks Game programs put Rust between 1.8x and 192x ahead
The Benchmarks Game team publishes per-program measurements for Rust and for Python 3. The table below takes the elapsed times listed on those pages for five programs, read on November 15, 2026, and divides the Python time by the Rust time; the ratios are our own division of the listed times. The Rust page records Rust 1.84.1 with LLVM 19.1.5; the Python page records Python 3.13.0. The timings are the Benchmarks Game team’s measurements.
| Program | Input size | Rust elapsed (s) | Python elapsed (s) | Python time divided by Rust time |
|---|---|---|---|---|
| mandelbrot | 16,000 | 0.954 | 182.938 | 192x |
| n-body | 50,000,000 | 2.192 | 372.412 | 170x |
| fannkuch-redux | 12 | 3.807 | 311.175 | 82x |
| binary-trees | 21 | 1.065 | 33.368 | 31x |
| regex-redux | 5,000,000 | 0.784 | 1.409 | 1.8x |
No single multiplier describes these rows. Mandelbrot and n-body show the widest gaps, at 192x and 170x; fannkuch-redux is 82x and binary-trees 31x; regex-redux is only 1.8x. Each row compares one submitted program per language, and the pages number them differently (regex-redux is #7 for Rust and #2 for Python), so a ratio describes those two submissions, not the languages in general. A blanket figure such as “Rust is many times faster” is therefore only useful once you know which of these rows your slow code resembles, which is what profiling tells you.
Free-threaded Python adds parallel threads, not a memory model
The free-threading HOWTO states that starting with the 3.13 release CPython supports a build with the global interpreter lock (GIL) disabled, so threads can run in parallel on available CPU cores. That removes one limit on CPU-bound Python threads. It does not give Python ownership checking: the documentation’s guidance for shared data is explicit synchronization, and the interpreter still reclaims objects by reference counting.
| Topic | What the Python documentation says |
|---|---|
| Availability | A free-threaded build with the GIL disabled has existed since 3.13; threads run in parallel across cores. |
| Identifying a build | python -VV and sys.version contain “free-threading build”; sys._is_gil_enabled() reports whether the GIL is disabled in the running process. |
| C extensions | Importing a C-API extension not marked as supporting free threading can automatically enable the GIL, with a warning. |
| Shared data | Use threading.Lock or other synchronization primitives instead of relying on the internal locks of built-in types. |
| Single-thread cost | On the pyperformance suite, average overhead ranges from about 1% on macOS aarch64 to 8% on x86-64 Linux. |
| Reference counting | The free-threaded build uses biased reference counting, with a fast path for objects owned by the current thread. |
The extension row is the one that decides whether the build helps you. If any module you import lacks free-threading support, the process can fall back to running with the GIL, so check the state after all your imports have run:
python -VV
python -c "import sys; print(sys._is_gil_enabled())"
The overhead row means single-threaded code can get slightly slower, by an amount that depends on workload and hardware. Free threading is therefore worth testing when your bottleneck is parallel Python code and your extensions are compatible. It is not a substitute for the benchmark gaps above, which are about the cost of executing each program, and it does not change the choice if you want the compiler to police ownership.
Python’s interpreter speed has its own track. The What’s New page for Python 3.14, read on November 15, 2026, says that version was released on 7 October 2025. The benchmark rows above use Python 3.13.0, so they do not reflect 3.14, and per-program ratios that compare two separate submissions say little about what a newer interpreter release changes.
Patch releases have also moved on. The python.org page for 3.14.7 carries the note that it “has been superseded by Python 3.14.10”. As of November 15, 2026, the python.org versions page lists 3.14.10 (25 October 2026), 3.13.18 (25 October 2026) and 3.10.22 (1 October 2026) as the latest patch releases of their series; 3.13.15 and 3.10.21 are superseded. The benchmark page records 3.13.0, while the latest 3.13 patch release is 3.13.18, so check which patch release your own interpreter or deployment image carries before comparing results.
Polars, pydantic-core and tokenizers already put Rust behind Python imports
The PyO3 guide lists projects built on it, and several are libraries Python developers already install. Each one shows the mixed option in practice: the caller keeps writing Python while the performance-sensitive part is Rust.
| Project | Role according to the PyO3 project list |
|---|---|
| polars | Fast multi-threaded DataFrame library in Rust, with Python and Node.js interfaces |
| pydantic-core | Core validation logic for pydantic, written in Rust |
| tokenizers | Python bindings to the Hugging Face tokenizers (NLP) library, written in Rust |
| pycrdt | Python bindings for the Rust CRDT implementation Yrs |
Pydantic’s V2 announcement is useful when you estimate what a rewrite will buy. It says V2 will be significantly faster than its predecessor as a result of the move to Rust for validation logic and significant improvements in how validation objects are structured. The speed-up is credited to two changes, so part of any gain can come from redesigning the data path rather than from the language. That argues for replacing one component, behind an interface your Python code already uses, instead of rewriting a whole application.
Rust also appears in uv, proxies, microVMs, inference engines and the Linux kernel
Rust also appears in tooling that Python teams use directly. Astral’s Rust-built uv is described in the uv documentation as “A single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more” and as “10-100x faster than pip”. That is the vendor’s own figure, as read on November 15, 2026, and it concerns package installation, so it is not comparable with the program ratios in the table above.
Several infrastructure projects describe their own use of Rust, and each figure below is the project’s own statement, as read on November 15, 2026. Cloudflare’s Pingora post describes “a new HTTP proxy we’ve built in-house using Rust that serves over 1 trillion requests a day”. The Firecracker project page says its design “enables a < 125 ms startup time and a < 5 MiB memory footprint”. Cloudflare’s Infire post says its Rust-based inference engine “completes inference tasks up to 7% faster than vLLM 0.10.0 on unloaded machines equipped with an H100 NVL GPU”. The Linux kernel’s Rust documentation says Rust support went into mainline in v6.1 “in order to help in determining whether Rust as a language was suitable for the kernel, i.e. worth the tradeoffs”. These describe different systems and measures, so none of them is comparable with the Python-versus-Rust program ratios above.
Profile first, then build one extension with PyO3 and maturin
The PyO3 guide requires Rust 1.85 or greater and supports CPython 3.9 or greater. Rust’s release notes (read November 15, 2026) list “The 2024 Edition is now stable” alongside stabilized async closures under Version 1.85.0 (2025-02-20). The Rust blog’s release list shows Rust 1.97.0 on July 9, 2026 and the patch 1.97.1 on July 16, 2026, and Rust keeps a six-week release cadence, so a current toolchain is well past that minimum. Start with the Python profiler: its documentation says internal-time statistics identify “hot loops” worth careful optimization, while cumulative-time statistics identify high-level mistakes in algorithm selection. A function that is slow because of the algorithm should be fixed in Python before it is ported. The profiler documentation keeps cProfile as a backward-compatible alias to profiling.tracing, so existing cProfile commands still work.
The scaffold below follows the PyO3 getting-started instructions: create a directory and a virtual environment, install maturin, run maturin init and choose the pyo3 bindings when asked, then build. Because maturin init generates the package source, you edit the generated Rust rather than writing the project skeleton by hand.
# 1. Find the hot spots: internal time points at hot loops
python -m cProfile -s tottime your_app.py
# 2. Create the extension project (PyO3 guide)
mkdir string_sum
cd string_sum
python -m venv .env
source .env/bin/activate
pip install maturin
maturin init . # choose pyo3 bindings when prompted
# 3. Build with optimizations and install into the active virtualenv
maturin develop --release
Between steps 2 and 3 you replace the generated example with your own hotspot. The files below are a sketch of that edit, not the guide’s verbatim output: process_data and myrust are example names of ours, the generated files differ by PyO3 and maturin version, and you should keep the pyo3 dependency line that maturin init generated. In Cargo.toml, the library name must match the Python module name and the crate type must be a C-compatible dynamic library:
[lib]
name = "myrust"
crate-type = ["cdylib"]
# keep the [dependencies] section that maturin init generated
In src/lib.rs, mark the function you are moving with #[pyfunction] and register it in the module function, whose name is the module name Python imports:
use pyo3::prelude::*;
#[pyfunction]
fn process_data(data: &str) -> usize {
data.split_whitespace().count()
}
#[pymodule]
fn myrust(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(process_data, m)?)?;
Ok(())
}
After maturin develop --release, Python calls it like any other module: import myrust, then myrust.process_data(text). The caller’s interface stays the same, which is what lets you swap the Rust version in and out while you measure.
maturin develop builds the package and installs it into the activated virtual environment. The guide says to use --release when checking runtime performance, and to edit the Rust source and re-run the command to recompile. Measure the same workload again with the release build, and keep the extension only if the profile shows a gain on your function. The table of benchmark programs above is the reason to expect different gains for different functions.
JetBrains ranks Rust high on promise and pay, and Python first on usage
The JetBrains State of Developer Ecosystem 2026 report is based on 28,945 developers from 198 countries and regions, surveyed from May to July 2026 and weighted by region, employment status and programming language use. What it says about these two languages is a set of rankings.
| Finding | Python | Rust |
|---|---|---|
| Most widely used language | 65%, the first time Python has overtaken JavaScript | Not named in this finding |
| Language Promise Index (five-year growth, adoption intent, loyalty) | Third | Second, behind TypeScript |
| Highest-paid language skills | Not named in this finding | Leads the category alongside Go |
| Languages developers most want to adopt next | Not named in this finding | Rust and Go |
Python’s 65% is a usage share, and Rust’s placements are positions in a ranking, so the report gives no basis for a dollar premium or a vacancy count. The highest-paid finding places Rust in a category it shares with Go; our Rust vs Go comparison covers choosing between those two.
Start from the work you expect to do, and let a profile decide the rest
For scripting, automation and data work, begin with Python: the tutorial describes that fit, and the JetBrains survey shows it is the most widely used language among respondents. You can still benefit from Rust without writing any, because libraries such as Polars and pydantic-core expose Python interfaces over Rust engines.
For a Python application with a slow function, stay in Python, profile, and move one measured hotspot into a PyO3 extension. Learning enough Rust to write that one function means learning ownership, which the Rust Book says takes time, but it keeps the rest of the codebase and its Python interface intact. Check the result against a release build, and treat the benchmark ratios as a reminder that the gain depends on the function you move.
For components that should manage their own memory and resources, or where you want the compiler to enforce ownership from the start, choose Rust and plan for the learning period; our Zig vs Rust comparison covers the choice between Rust and Zig. If the goal is a career direction rather than a project, the survey supports learning Python for breadth of use and adding Rust for the performance-critical layer. Both Rust rankings are consistent with that, and neither is a salary promise.




