PyCon Lithuania 2024

Using Rust & PyO3 to make Pydantic v2 even faster
2024-04-04 , Room 111

In this talk we'll review some of the changes we've made to Pydantic since 2.0 to push performance even further. This is possible largely because Pydantic chose to implement the core in Rust. We'll focus on two main topics:

  • Come learn about optimizations Pydantic has been working on since 2.0
  • Come see our draft ideas how Pydantic v3 could be even faster than v2

You should leave this talk excited about performance wins for your apps using Pydantic and inspired to try Rust in your own code.


We released Pydantic 2.0 in June 2023. One of the headline features was the new core implemented in Rust, using PyO3; this allowed us to gain an order of magnitude of performance compared to the pure-Python implementation of Pydantic v1.

Our journey didn't stop there. Since 2.0 we've been busy making Pydantic even faster. A lot of this work is possible because the Rust core allows us to make fine-tune adjustments which pure-Python would not be able to express.

In this talk we'll review some of the changes we've been working on in PyO3 and Pydantic since 2.0 to push performance even further, and where we could go for Pydantic v3.

While Rust code will be very relevant to this talk, no knowledge of Rust is expected. Ideally you'll also walk away from this talk excited for possibilities to optimize your own code using a sprinkle of Rust. PyO3 aims to make it accessible for many Python developers to pick up Rust and start optimizing!

David is a Staff Software Engineer at Pydantic and lead maintainer of PyO3, and a Python developer for a decade. Ever since discovering Rust shortly after its 1.0 release in 2015 David has been passionate about using Rust as well as Python. In 2019 David found PyO3 needing more contributors and previous experience working in a mixed Python/C++ codebase had left him with plenty of ideas of how Rust & Python can flourish together. Nowadays Rust is powering the core of many Python packages and David works to continue to build this growing ecosystem.