If you're writing a compiled extension, you can use Rust. Or Cython. Or C. Or C++. Which should you use?
TL;DR:
* If you're wrapping existing C library, I'd use Cython.
* If you're wrapping existing C++ library, I'd use PyBind11 (no personal experience, but it's based on Boost::Python, which I have happily used). Cython in theory does C++ but it's a frustrating, limited experience.
* If you're writing a tiny library and you don't know Rust, and you're not worried about memory safety, Cython is nice.
* For anything involving writing extensive new low-level code, Rust with PyO3. Memory safety _will_ bite you in the ass. Concurrency is vastly easier with Rust. You get a package manager for dependencies. You're not writing a pile of code in a language without good tooling (Cython).
TL;DR:
* If you're wrapping existing C library, I'd use Cython.
* If you're wrapping existing C++ library, I'd use PyBind11 (no personal experience, but it's based on Boost::Python, which I have happily used). Cython in theory does C++ but it's a frustrating, limited experience.
* If you're writing a tiny library and you don't know Rust, and you're not worried about memory safety, Cython is nice.
* For anything involving writing extensive new low-level code, Rust with PyO3. Memory safety _will_ bite you in the ass. Concurrency is vastly easier with Rust. You get a package manager for dependencies. You're not writing a pile of code in a language without good tooling (Cython).
Long form, with more alternatives and use cases: https://pythonspeed.com/articles/rust-cython-python-extensio...