
Remote Workshop: Rust-Python Interoperability
Python has served you well: you spun up a prototype and iterated quickly, keeping up with the evolving requirements of a successful product. Nonetheless, as time goes on, cracks are starting to show up: an endpoint is slower than it needs to be, a data processing job that took seconds now takes almost an hour, and your infrastructure bill is growing too fast compared to the size of your user base. Engineers are starting to whisper: is it time for a rewrite? Should we pause feature development to rebuild everything on more solid foundations? That's an option, but it's expensive.
There's another path: rather than throwing away your entire Python codebase to start over, you analyse your application and isolate the performance-critical bits—the so-called "hot modules" where your application spends most of its time. You will rewrite those in Rust and package them as a Python native extension. This workshop will teach you how.
We will cover the PyO3
crate, the subtleties of Python's Global interpreter lock, and typical examples that may arise in your daily Rust-Python interoperability work. By the end of the session, you will be well-equipped to seamlessly replace your slow Python modules with easy-to-use and blazingly fast Rust modules.
Tickets
Schedule
February 27th, 2025
February 28th, 2025
Additional Information
Mainmatter Workshop: Rust-Python Interoperability
Duration & location
The workshop takes place over two afternoons on February 27th, and 28th, 14:00 to 18:00 CET each. That allows participants to use the mornings to exercise or keep up with work.
The workshop is run completely online and remote.
Number of participants
To ensure the highest quality, we accept up to 20 participants.
For whom?
We assume you are familiar with Rust and Python, but we don't assume any prior interoperability knowledge. We will provide a brief explanation and references whenever we rely on advanced features in either language.
Prerequisites
We will send a detailed list of instructions for preparation, including the installation of tools, etc. Additionally, we will share a Github project with workshop materials. This information will be provided closer to the workshop date.
Workshop Contents
-
Introduction to Rust-Python Interoperability: We kick off with looking at the advantages of combining Rust and Python, understanding where each language shines and why interoperability is valuable. This module introduces tools like
PyO3
, which enables Rust code integration within Python environments, andmaturin
, a library for building, packaging and publishing Python extensions written in Rust. -
Building Python Extensions in Rust: We'll continue with the process of creating Python-callable Rust functions, setting up projects using
PyO3
, and configuring the development environment to handle Rust extensions in Python. - Managing Data and Types: Next, participants will learn how to handle complex data structures shared between Rust and Python, with a focus on type conversions, data ownership, and ensuring memory safety across both languages.
- Concurrency and the GIL: The workshop covers Python’s Global Interpreter Lock (GIL) and strategies for concurrent programming, including async programming in Rust that can enhance Python’s parallel processing capabilities.
-
Creating Python Classes with Rust: We move on to explore creating Python-accessible classes directly in Rust using
PyO3
's#[pyclass]
attribute. This module teaches struct definition, implementing methods, and adding Rust-based functionality to Python classes. - Static Methods and Inheritance: The final module details adding static methods to Rust-backed Python classes, along with managing inheritance and visibility in Python environments.
Workshop facilitators
Luca Palmieri builds technology products for a living and is Mainmatter's Principal Engineering Consultant. His current focus is on backend development, software architecture and the Rust programming language. He is the author of "Zero to Production in Rust" and Mainmatter's Rust expert.
Henk is a seasoned Rust engineer with experience in backend development and embedded software engineering, working as Rust Engineering Consultant at Mainmatter. Henk is maintainer of teach-rs, the modular, reusable university course platform for Rust. As a member of Rust's Embedded devices Working Group, Henk helps out creating educational material for using Rust on limited systems.
About Mainmatter
Mainmatter is an engineering consultancy that helps teams adopt and succeed with Rust. We offer strategic advice, training, and team reinforcement. We are also the organizers behind the EuroRust conference.