# Pydantic v2's Rust core hides a costly secret at the Python boundary

Original title: Libraries Run Rust Inside Python (With PyO3)

> Hacker News story 49685037 · language: en · submitted 2026-09-13
> Web version: https://zeli.app/story/49685037
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 69 · by [lumpa](<https://news.ycombinator.com/user?id=lumpa>) · 💬 40
[original](<https://belderbos.dev/blog/how-libraries-run-rust-inside-python/>) · [HN discussion](<https://news.ycombinator.com/item?id=49685037>)

## Summary

Pydantic v2's speed comes from pydantic-core, a Rust extension built with PyO3. This post walks through a JSON parser in Rust exposed to Python via PyO3 and maturin. The surprising bottleneck: converting the parsed Rust tree into Python objects can cost more than the parsing itself. For large documents, that materialization loop dominates end-to-end time. The advice: profile the boundary, not just the algorithm, and consider lazy views instead of eagerly building the whole tree.

## Key quote

> A document with 100,000 values means on the order of 100,000 Python objects being created at the boundary, all after parsing is completely done.

## HN discussion (40 comments)

### [simonw](<https://news.ycombinator.com/item?id=49685369>)

> I was a bit nervous about this trend when it started picking up because I care about Pyodide (Python running via WebAssembly) and libraries that use PyO3 might not work in Pyodide.
>
> Thankfully that's now been mostly solved - you can compile and publish WASM builds of Rust or C extensions on PyPI now and a Pyodide can then use them.
>
> Here's the WASM build of the Rust-including Pydantic-core package for example: https://pypi.org/project/pydantic_core/#pydantic_core-2.49.0...

### [the__alchemist](<https://news.ycombinator.com/item?id=49685302>)

> This is a nice party trick! I use it to provide easy installation of software that is written in rust, but is primarily used by Python users. (e.g.: Biology tools) They can do `pip install <name>`, since some people prefer this over downloading executables/installers. Bonus: Maturin/PyO3 can build "manylinux" binaries automatically, which helps with the Linux ABI diaspora.

### [skeledrew](<https://news.ycombinator.com/item?id=49685557>)

> But does it work everywhere Python works? My main issue with this Rust move has always been compatibility. Python can be embedded and ran in a heck of a lot of places. What's the story when libraries that I may want to depend on are actually implemented in Rust and my target doesn't/can't handle the toolchain and there's no build target?

### [roywiggins](<https://news.ycombinator.com/item?id=49685418>)

> \> reach for, a Rust extension does the work
>
> ai; dr, sorry

### [startup_zombie_](<https://news.ycombinator.com/item?id=49686212>)

> How much of the existing PyPI ecosystem do you think could realistically work this way without package authors doing anything specifically for WASM?

---

## Cite

- Page: https://zeli.app/story/49685037
- Date: 2026-09-13
- Source: belderbos.dev (https://belderbos.dev/blog/how-libraries-run-rust-inside-python/)
- Hacker News: https://news.ycombinator.com/item?id=49685037

## Other languages

- zh: https://zeli.app/zh/story/49685037 · markdown: https://zeli.app/zh/story/49685037.md
- ja: https://zeli.app/ja/story/49685037 · markdown: https://zeli.app/ja/story/49685037.md
- ko: https://zeli.app/ko/story/49685037 · markdown: https://zeli.app/ko/story/49685037.md
- de: https://zeli.app/de/story/49685037 · markdown: https://zeli.app/de/story/49685037.md
- es: https://zeli.app/es/story/49685037 · markdown: https://zeli.app/es/story/49685037.md
- ru: https://zeli.app/ru/story/49685037 · markdown: https://zeli.app/ru/story/49685037.md
