<story><title>Calling Rust from Python using PyO3</title><url>http://saidvandeklundert.net/learn/2021-11-18-calling-rust-from-python-using-pyo3/</url></story><parent_chain></parent_chain><comment><author>rdedev</author><text>Check out apache arrow in rust for transferring large amounts data between rust and python. With it you can get zero copy transfers between the languages. Afaik there is some performance penalty involved when converting python types to native rust types.&lt;p&gt;It used to be hard to do such transfers between rust and python using arrow but from v3 or v4, arrow implementation in rust started supporting the c data interface. Creating the array in rust and sending it to python might involve leaking a boxed object though&lt;p&gt;Check this out if you want to see how
&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;jhoekx&amp;#x2F;python-rust-arrow-interop-example&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;lib.rs&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;jhoekx&amp;#x2F;python-rust-arrow-interop-example&amp;#x2F;...&lt;/a&gt;</text></comment>
<story><title>Calling Rust from Python using PyO3</title><url>http://saidvandeklundert.net/learn/2021-11-18-calling-rust-from-python-using-pyo3/</url></story><parent_chain></parent_chain><comment><author>Grollicus</author><text>I recently wanted to use some rust crates from Python and decided to give PyO3 a go and I must say it works really well.&lt;p&gt;Took about one evening to plug it all together and get it running. The guide at pyo3.rs was really helpful and maturin to build binary packages just works. You pass in python types and they arrive as rust-native types. Makes writing code feel very native.&lt;p&gt;The result: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;Grollicus&amp;#x2F;pyttfwrap&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;Grollicus&amp;#x2F;pyttfwrap&lt;/a&gt; takes a string and splits it as it would wrap when rendered with a given TTF font. Most of the code is about keeping a reference to the loaded font as that&amp;#x27;s an expensive operation.&lt;p&gt;Was some great fun and I&amp;#x27;m sure I&amp;#x27;ll use it some more.</text></comment>