Close-up photo of 3 snake bodies (or 3 parts of the same snake body) stacked on top of each other.

All Rust Workshops

Rust-Python Interoperability

1 day Bookable for teams – on-site or remote

About This Workshop

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.

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.

Bookable for teams

1 day

On-site or remote

Book for your team

Syllabus

  1. 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, and maturin, a library for building, packaging and publishing Python extensions written in Rust.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

FAQ

Placeholder! What software do I need to have?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

Placeholder! What hardware do I need to have?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

Placeholder! How will the workshop be held?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

Placeholder! How will the workshop be held?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

Your mentor

Luca Palmieri

Principal Engineering Consultant

Luca Palmieri builds technology products for a living. His current focus is on backend development, software architecture and the Rust programming language. He is the author of "Zero to Production in Rust".

Our Attendees Say...

[…] Really enjoyed the training. The approach of self-paced, bit of background reading and including solutions, works for me.
Onsite attendee
These 8 hours might have saved me from naively starting a PyO3 project and waste a lot of effort and my companies money :) […]
Onsite attendee

Who we are

We are Mainmatter and we Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl.

Rust Workshops

We offer a range of workshops bookable for teams that want to grow – on-site or remote. We're also happy to prepare custom workshops – get in touch with us to talk about what curriculum fits your team best!

We are Trusted by

Bookable for teams

1 day

On-site or remote

Book for your team

Can't Find the Right Workshops for Your Team?

We are happy to tailor the curriculum to your needs. We can combine multiple workshops, pick and choose modules, as well as develop new content if desired.
Get in Touch

Book This Workshop

Our mentors look forward to working with your team and unlocking new capabilities.

Send us a message

Your message is being sent…

Unable to send message.

Please try again later or contact us at info@mainmatter.com

Thank you!

We will be in touch soon.

Rust-Python Interoperability