top | item 41139595

RustPython: A Python Interpreter Written in Rust

196 points| bovem | 1 year ago |github.com

70 comments

order

stavros|1 year ago

I don't understand how it's possible that we just randomly come across a project that just casually implements a Python interpreter in Rust. Don't these things take a massive amount of effort? Wouldn't this be making waves much earlier in its development process?

I feel the same way about Ruff, for example. One day it was "black all the things" and the next it's "btw we just reimplemented the entire Python formatting/linting ecosystem in Rust, and it's 100x faster, no biggie".

What's happening? Is it just so much easier to write stuff in Rust that projects like these pop out of people's heads, fully-formed? It boggles the mind.

PaulHoule|1 year ago

For me the "uv" manager has changed my Python experience because: (1) it has a correct resolver whereas "pip" certainly doesn't and I'm not sure about poetry, (2) it is crazy fast, (3) "uv" is just a binary which I can pip into my system.

(3) is important because if it was written in Javascript or Java or Python or .NET or many other languages I'd have to learn something about the runtimes of those environment to get it working. If it was written in Python it would have to deal with the bootstrapping problem that it ought to have it's own Python installation separate from the one that it is manipulating so it can't have conflicts with that environment. (e.g. how many times have I busted my poetry?) I can use "uv" or "ruff" without learning anything about Rust!

As for (2) the speed of "uv" has as much to do with better algorithms and caching as it does with being in Rust and thus much faster than Python. I think you could have done better than Poetry in Python but "uv" is transformative in that it can often build an environment in seconds or less whereas with "poetry" or "pip" or "conda" I might have time to pound out a few posts on HN. I used to avoid creating new Python environments as much as possible but now it is fast, easy, and even fun.

I bet it is more work to write "uv" in rust as opposed to a similar tool in Python but the impact on the community is so huge because we can finally put problem (1) behind us and do it with speed, reliability and grace. I had notes on how to build a better python package management system and sometimes thought about trying it but I'd become convinced that the social problem of too many people finding half-baked tools like "pip" and "poetry" acceptable was intractable. Thanks to "uv" nobody will ever have to write one.

pansa2|1 year ago

> Don't these things take a massive amount of effort?

Yes, RustPython has been in development since at least 2018.

> Wouldn't this be making waves much earlier in its development process?

It's been posted on HN several times before: https://hn.algolia.com/?q=rustpython

ufmace|1 year ago

A quick check on the contributors page shows ~8ish heavy contributors working over the course of 6 years and 13k commits. That's a good thing to check for any project you're thinking about integrating with IMO.

That said, my experience has been that adding business features in Rust apps is quite fast indeed!

pbronez|1 year ago

Interesting that it relies on OpenSSL, either dynamically from the OS or vendored at compile time. I wonder what the implications would be for using something like rustls. You’d get TLS batteries included and kill a large external dependency… but possibly introduce behavior changes to low-level cryptographic operations, which is scary.

Still, the maintainers stated that they don’t plan to implement Python’s readline module because they already have a rust implementation of readline. A similar argument could apply here - use native rust implementations of dependencies and expose them via the expected Python APIs. This would break some ambitious Python programs, but those probably wouldn’t consider alternative runtimes anyway.

https://github.com/rustls/rustls

nextaccountic|1 year ago

Does numpy runs on rustpython? And other libraries used in ML (not expecting compatibility with huge libraries like torch or tensorflow, but rather, getting the leaves to work should be doable)

If not, is it at all possible to get numpy to work and other libraries written in native code? I see that rustpython also work in wasm: but what about compiling numpy's native code to wasm as well?

upbeat_general|1 year ago

Does this have faster startup times than cpython?

Every time I want to rewrite a shell function in python, I always hesitate due to the slow startup.

actinium226|1 year ago

How fast does it really need to be? On my M2 macbook air:

    $ time A=1 B=1 python -c "import os; print(int(os.getenv('A'))+int(os.getenv('B')))"
    2

    real 0m0.068s
    user 0m0.029s
    sys 0m0.026s

bdbdhxhdh|1 year ago

I curious why you would think so, since CPython is already written in C

nickpsecurity|1 year ago

I wonder if this would make Python web applications more secure at interpreter and library level.

Running it on hardened Linux, OpenBSD, or FreeBSD was a start. A Rust implementation might help.

I also miss setups like eCos RTOS where a GUI determined which features got compiled in. Strip each Python app down to just what it needs in the interpreter. Might squeeze it in L1-L2 cache that way, too. Aside from embedded (eg MicroPython), has anyone anything like that for use on servers?

pipeline_peak|1 year ago

If Rust makes its way into the Linux Kernel, another mature C project, I wouldn’t be surprised if a Rust interpreter replaces CPython.

Zamiel_Snawley|1 year ago

I don’t see it on the main read me, what are the limitations/incompatibilities with CPython at this point in time? How “drop in ready” is it?

rty32|1 year ago

This seems very weird to me. Anyone who is just slightly interested in the project would want to know if specs are fully implemented and this has parity with the "official implementation". Can't believe it's not in README.

kalger|1 year ago

[deleted]

jbernsteiniv|1 year ago

Does RustPython support the GIL? It would be ironic for a language with a crab as a mascot to not depend on having gills or at least one.

hughdbrown|1 year ago

There's no installable version for pyenv. In general, how well does this work with virtualenvs?

abdullahalharir|1 year ago

Are there any benchmarks made public in comparison with the python3 interpreter?

jeden|1 year ago

We waiting for Ruby ;)

jedisct1|1 year ago

A Python interpreter has to be written in every language.

haspok|1 year ago

Just as Doom runs on about any hardware you can think of.

cutler|1 year ago

While you're at it fix Python's crippled lambdas and ...

KolenCh|1 year ago

I wonder why you stops there midway in a sentence and only after reading the other comments I get what you mean … What problems you are referring to exactly, and how would they be fixed as an implementation but not at the language level?

JohnKemeny|1 year ago

What's wrong with Ellipsis?

bitzun|1 year ago

This project doesn't seem to be adhering to the terms of the license of the original CPython modules that have been copied into its source repository.

bee_rider|1 year ago

What are they violating, out of curiosity?

jdeaton|1 year ago

does it have a GIL

galdosdi|1 year ago

idk but Jython didn't. So I don't think there's anything inherent in the language outside of CPython that calls for it.