4 ms·
Writing and publishing a Python module in Rust
- kzrdude 5y agoI used inline_python once (powered by PyO3) and it was extremely easy to move some data from Rust into numpy and back. Used to double-check an algorithm.
- turbinerneiter 5y agoI used this very guide a while ago and found it and the tools it teaches very enjoyable. Downright fun to use. On the Rust side, I had to learn Box and RefCell to achieve my goals.
- woodruffw 5y agoI’m glad you found it enjoyable! Hopefully it was helpful as well :-)
- prionassembly 5y agoI've been writing Rust code that imports in Python with Pyo3 and Maturin.
- ufmace 5y agoIt's really cool how easy it is to interact with the Python environment, and that you can do it without actually writing any Python or needing a Rust compiler on the system you're using the Python package with. The trouble, though, is I looked through the code for a bit, and maybe I'm missing something, but I don't understand why this needs to be in Rust. I'd lean against combining languages like this unless there's a clear benefit from doing so that you can't get by just writing Python.
- deleted 5y ago[deleted]
- woodruffw 5y agoI’m the author of the package in question, so I can try to answer that. The first (and lazy) answer is that it was an educational exercise: I wanted to try my hand at writing in Python package in Rust, and this particular need afforded itself of me. The second answer is that the package in question contains a (basic) parser, and it’s my opinion that Rust is particularly well suited to this domain: you should ideally only write a /proc/…/maps parser exactly once, with strong modeling of all valid and invalid states. Rust gives us that strong modeling for free (to say nothing of performance and memory safety), and it binds easily to other languages.
- godisdad 5y agoInteresting read. If wheels existed for Ruby (maybe they do?) having an approach for things like nokogiri would probably put a dent in climate change but avoiding Swig-y recompilation during module installation
- woodruffw 5y agoI haven’t meaningfully exercised my Ruby skills in a while, but you can probably fake a wheel-style gem by having extconf or something similar fetch an appropriate build from a server instead of performing the build locally. That would be an awful hack, which is why it wouldn’t surprise me to find out that people are doing it :-)