Hey all, just wanted to tell you about Pyonear, a project I’m working on to provide Python wrappers for near-primitives
and other Rust crates that comprise the backbone of near-api-rs
.
I’m currently seeking a grant for this, so here are some details on what I’m building and why:
Pyonear (PyO3 + NEAR) is a high-performance Python library for interacting with NEAR, built primarily by wrapping the NEAR Rust crates (e.g. near-primitives) in Python. It uses PyO3 to run NEAR’s Rust code in Python, providing Python users with fast, familiar and robust solutions for foundational NEAR problems (e.g. public key cryptography, building transactions and parsing accounts). The first release will provide comprehensive Python wrappers for the Rust primitives that enable building, signing and serializing transactions.
Why me?
I have a lot of experience building Python blockchain Python libraries, including libraries that call Rust under the hood. I am the top contributor to solana-py
, and I am the author of solders, a Rust-based Python library used by solana-py
under the hood.
Why wrap Rust code instead of just using Python?
Here are the main benefits to using the NEAR Rust crates:
- The hard problems are already solved. We don’t need to reimplement things like signing and serialization because we are calling code that already takes care of it.
- Ease of upgrades: related to the above, it’s easier to accommodate changes to the NEAR protocol. For example, when Solana added a new Transaction version, I was able to add support for it in
solders
before I even understood how it worked. - Performance: while there are many cases where speed isn’t as important as people think, it is still very useful for things like data engineering where N is large. Based on what I observed with Solders, I estimate Pyonear would be 10-100x faster at the things it does than pure Python.
Rust is becoming increasingly popular for Python libraries. Two recent examples are polars
, the very fast dataframe library, and pydantic
, which recently started using Rust to speed up its core operations.
Do end users need Rust installed?
No! I sometimes see this in comment sections and the like so I thought I’d take the time to clarify it. People who run pip install pyonear
are installing a prebuilt wheel for their platform. They don’t need the Rust toolchain at all for this.