a language that allows you to build high level abstractions, but without giving up low-level control – that is, control of how data is represented in memory, control of which threading model you want to use etc.
a language that can usually detect, during compilation, the worst parallelism and memory management errors (such as accessing data on different threads without synchronization, or using data after they have been deallocated), but gives you a hatch escape in the case you really know what you’re doing.
a language that, because it has no runtime, can be used to integrate with any runtime; you can write a native extension in Rust that is called by a program node.js, or by a python program, or by a program in ruby, lua etc. and, however, you can script a program in Rust using these languages. — “Elias Gabriel Amaral da Silva”
There is a bunch of Rust packages out there to help you extending Python with Rust.
I can mention
created by Armin Ronacher (the creator of Flask) and also
The Rust bindings for Python interpreter.
Everything you need to grow your career.
With your free Red Hat Developer program membership, unlock our library of cheat sheets and ebooks on next-generation application development.
See a complete reference list at the bottom of this article.
see it in action
For this post, I am going to use
, it’s the only one I have tested, it is compatible with stable version of Rust and found it straightforward to use.
is a fork of rust-cpython, comes with many improvements, but works only with the nightly version of Rust, so I prefered to use the stable for this post, anyway the examples here must work also with PyO3.
It is easy to write Rust functions and import from Python and as you will see by the benchmarks it worth in terms of performance.
The distribution of your
will demand the Rust module to be compiled on the target system because of variation of environment and architecture, there will be a
stage which you don’t have when installing Pure Python libraries, you can make it easier using
or using the
to embed binary data in Python Wheels.
It creates a new Rust project in that same folder called pyext-myrustlib containing the Cargo.toml (cargo is the Rust package manager) and also a src/lib.rs (where we write our library implementation).
We serve the builders. The problem solvers who create careers with code.
Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.