
PyO3: Python  Rust binding - blacksmythe
https://github.com/PyO3/pyo3
======
fafhrd91
I also wrote asyncio event loop, based on tokio-rs, using this binding. So it
is possible to write complex python extensions in Rust.

[https://github.com/PyO3/tokio](https://github.com/PyO3/tokio)

------
kevinnk
Very cool! Good binding libraries between C++ and Python have been super
useful for my projects in the past, and I'm glad to see something similar
developed for Rust.

For anyone reading the comments first, this is a fork of rust-cpython. The
motivation for the fork is linked from the Readme:
[https://github.com/PyO3/pyo3/issues/55](https://github.com/PyO3/pyo3/issues/55)

------
Steeeve
It looks like you forked because rust-cpython was abandoned. I see that Dan
Grunwald pushed a commit in today after no activity since May. He probably
just went on summer vacation.

~~~
dgrunwald
rust-cpython will most likely stay abandoned; I rarely have the time (or
interest) to work on it. The commit today was me just finally finishing up a
change I started in February...

What happened with the fork: in May @fafhrd91 contacted me about joining the
project. When I had time to consider his request (on the following weekend),
he had already forked the project and deleted all his original pull requests.
He even deleted his bug report about that segfault he keeps mentioning when
comparing PyO3 to rust-cpython.

On the technical side, the API changes in PyO3 are interesting. It's kind of a
return to my original design (with `&'a PyObject<'p>`), but he makes it work
with just a single lifetime by using a "release pool" that temporarily holds
ownership over the python references. This does make the API significantly
nicer to use, at the cost of leaking any Python objects until the GIL is
released / until the extension module returns to the interpreter. For the
typical extension module usecase, this doesn't hurt much. But a long-running
loop that allocates a temporary Python object each iteration might run out of
memory due to this design.

~~~
saurik
> He even deleted his bug report about that segfault he keeps mentioning when
> comparing PyO3 to rust-cpython.

That is just sleazy :/.

~~~
1st1
Crazy things happen when one abandons his projects.

~~~
98182911
If the original trigger is "more than a couple of days response time for a PR"
that seems quite drastic though.

I certainly won't use this fork for social reasons.

------
welder
So this is for running Rust code from Python... Just curious, is there an
existing way to do the opposite and run Python code from Rust?

~~~
fafhrd91
this binding can be used both ways. check first example in readme. and
[https://github.com/PyO3/pyo3/blob/master/src/python.rs#L203](https://github.com/PyO3/pyo3/blob/master/src/python.rs#L203)

~~~
welder
Is this an alternative to cx_Freeze or py2exe?

~~~
fafhrd91
not really. it is an alternative to C and cython for extension development.

------
Cieplak
pybind11 is a similar library, but for interfacing with C++ from Python:

[https://github.com/pybind/pybind11](https://github.com/pybind/pybind11)

