-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is rust-cpython used for and how does it compare to cffi / ctypes / pybind11 / ...? #209
Comments
Fundamentally, there are two ways to interact with C from Python:
c extensions (C), pybind11 (C++), cython (a specialized dialect of Python), and rust-cpython (Rust) are all examples of option 1. ctypes and cffi are examples of option 2. Of those, the two that give you the most compile-time safety would be cython and rust-cpython. Cython is the simplest to get into, since you're essentially writing Python and then annotating it with types and other helpers, but it has limited potential for improved performance because of that. rust-cpython allows you to write Rust and then wrap it in API adapters to get maximum performance, but it means that you need to know how to write both Rust and Python. That said, rust-cpython does have the advantage that, since you can work in safe Rust, you should run into compiler errors rather than runtime crashes or memory corruption if you misunderstand how to use the APIs. |
Cool, thank you! I'm still not quite sure how to formulate this with my own words (and put it in a concise way in the README), but I think I got it :-) I'm not sure if I should now close this issue or leave it open. Do you think the beginning of the README is clear as it is? |
I do think that "Rust bindings for the python interpreter." would be better as "Rust bindings for the python interpreter, suitable for writing compiled Python extensions or embedding the Python runtime in Rust programs". As-is, you have to derive that latter part by reading the examples further down, which is less than ideal. |
I'm currently reading about how to speed up Python by using C and I found a couple of ways to "integrate" C into Python (bind C to Python? Execute C from Python? ... I'm not sure about the terminology):
Could you explain how rust-cpython relates to those? How does it compare to cffi / ctypes / pybind11 / ...?
(I haven't done anything with Rust so far and only super small projects with C / C++)
Thank you :-)
The text was updated successfully, but these errors were encountered: