Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
maturin
Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
-
rust-ndarray
ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
-
fast_vector_similarity
The Fast Vector Similarity Library is designed to provide efficient computation of various similarity measures between vectors.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
My new favorite way to write very fast libraries for Python is to just use Rust and Maturin:
https://github.com/PyO3/maturin
It basically automates everything for you. If you use it with Github actions, it will compile wheels for you on each release for every platform and python version you want, and even upload them to PyPi (pip) for you. Everything feels very modern and well thought out. People really care about good tooling in the Rust world.
I would love some examples of how to do non-trivial data interop between Rust and Python. My experience is that PyO3/Maturin is excellent when converting between simple datatypes but conversions get difficult when there are non-standard types, e.g. Python Numpy arrays or Rust ndarrays or whatever other custom thing.
Polars seems to have a good model where it uses the Arrow in memory format, which has implementations in Python and Rust, and makes a lot of the ndarray stuff easier. However, if the Rust libraries are not written with Arrow first, they become quite hard to work with. For example, there are many libraries written with https://github.com/rust-ndarray/ndarray, which is challenging to interop with Numpy.
(I am not an expert at all, please correct me if my characterizations are wrong!)
You can see how I did something similar in my library here:
https://github.com/Dicklesworthstone/fast_vector_similarity/...
Basically you use ndarray instead of numpy, try to vectorize anything you can, and for the for loops that can’t be vectorized, you can use rayon to do them in parallel.
Related posts
- Robyn Finds a New Nest: Joining the Sparckles Open-Source Organization
- Robyn – A Python Web Framework with a Rust Runtime
- Which programming language to focus on for my PhD journey in bioinformatics?
- Robyn v0.32.0 Introduces SubRouters – A Compact Way to Group Routes
- Stream processing framework for a new project in Python