This is a nice party trick! I use it to provide easy installation of software that is written in rust, but is primarily used by Python users. (e.g.: Biology tools) They can do `pip install `, since some people prefer this over downloading executables/installers. Bonus: Maturin/PyO3 can build "manylinux" binaries automatically, which helps with the Linux ABI diaspora.
Libraries Run Rust Inside Python (With PyO3)
11–20 of 41 posts
Re: Libraries Run Rust Inside Python (With PyO3)
#12Re: Libraries Run Rust Inside Python (With PyO3)
#13I was a bit nervous about this trend when it started picking up because I care about Pyodide (Python running via WebAssembly) and libraries that use PyO3 might not work in Pyodide. Thankfully that's now been mostly solved - you can compile and publish WASM builds of Rust or C extensions on PyPI now and a Pyodide can then use them. Here's the WASM build of the Rust-including Pydantic-core package for example: https://…
I'm kind of surprised to hear that was a concern because my perception is that PyO3 is more analogous to wrapping native C code in Python libraries (which is pretty well established since long before either Rust or WASM), and Pyodide seems more like something for use in browsers rather on the server-side. When I looked into this earlier this year, trying to run Python via WASM on the server side with Pyodide had a bu…
Re: Libraries Run Rust Inside Python (With PyO3)
#14Why not just run C inside of Python?
Re: Libraries Run Rust Inside Python (With PyO3)
#15But does it work everywhere Python works? My main issue with this Rust move has always been compatibility. Python can be embedded and ran in a heck of a lot of places. What's the story when libraries that I may want to depend on are actually implemented in Rust and my target doesn't/can't handle the toolchain and there's no build target?
It won't work in those cases. Do you have explicit examples? I suspect this won't come up much as Rust has, IME, much broader target support. (Including platforms without a GPOS)
Re: Libraries Run Rust Inside Python (With PyO3)
#16Also the article reeks of AI slop, it’s just trying to sell you a Rust course.
Re: Libraries Run Rust Inside Python (With PyO3)
#17They’re not running Rust they’re running machine code compiled with the Rust compiler. Like many other Python libraries such as numpy are running machine code compiled with C++, C or Fortran. That was always the case for Python and is its main selling point, it’s a slow but easy to write glue language that can make faster native code scriptable. Also the article reeks of AI slop, it’s just trying to sell you a Rust c…
Re: Libraries Run Rust Inside Python (With PyO3)
#18Earlier quoted context omitted.
It won't work in those cases. Do you have explicit examples? I suspect this won't come up much as Rust has, IME, much broader target support. (Including platforms without a GPOS)
I can't come up with any cases where cpython would compile that rustc can't target. There are some more niche interpreters that can run on embedded stuff with no rustc support, but they are also subsets of python so it isn't like you can just pull a wheel file and expect it to work
Re: Libraries Run Rust Inside Python (With PyO3)
#19They’re not running Rust they’re running machine code compiled with the Rust compiler. Like many other Python libraries such as numpy are running machine code compiled with C++, C or Fortran. That was always the case for Python and is its main selling point, it’s a slow but easy to write glue language that can make faster native code scriptable. Also the article reeks of AI slop, it’s just trying to sell you a Rust c…
One main difference is that pyo3 is safer and easier to use to build said modules and have them work correctly without issues. Thus modules which hadn’t been worth it before to build in this manner suddenly become so