PyCon APAC 2025

[Workshop] PyO3 202 - Support Python Async and Multithreading in PyO3
2025-03-01 , SS 117

Part of the reason why we would want to write Rust code for a Python library is for speed, another is to unlock the power of multithreading. In this workshop, we will look into advanced topics in PyO3 regarding support async in Python and how to do multithreading with PyO3.


Prerequsit

Please note that in this workshop, besides assuming that attendees have experience programming async in Python, attendees are required to have basic knowledge of Rust. Attendees are highly advised to go over the Rust Book to make sure they understand coding in Rust. Attendees are also advised to be already familiar with PyO3. If they are new to PyO3, first doing the PyO3 101 workshop would be ideal.

Target audience

Developers who would like to create powerful Python libraries that can support async in Python and speed up tasks with multithreading.

Goal

Deepend attendees' knowledge in PyO3, and strengthen understanding of parallelism in Python and Rust.

Outline

Part 1 - introduction and revision of PyO3 (30 mins)
- a recap of what we learned in PyO3 101
- about async and multithreading in Python and in Rust

15 mins break + Q&A

Part 2 - Support async and await in Python (60 mins)
- creating Python async functions with PyO3 (some coding exercises)
- troubleshooting for async (some coding exercises)

15 mins break + Q&A

Part 3 - Multithreading (90 mins)
- introduction of multithreading in Rust (some coding exercises)
- multithreading in PyO3 (some coding exercises)
- Free-threaded CPython and benchmarking (some coding exercises)
- Thread safety (discussion)


Audience Level:

Advanced

Category:

Advanced and Core Python

Workshop Duration:

2 hours

After having a career as a Data Scientist and Developer Advocate, Cheuk dedicated her work to the open-source community. Currently, she is working as AI developer advocate for JetBrains. She has co-founded Humble Data, a beginner Python workshop that has been happening around the world. She has served the EuroPython Society board for two years and is now a fellow and director of the Python Software Foundation.

This speaker also appears in: