What does HackerNews think of pybind11?

Seamless operability between C++11 and Python

Language: C++

#19 in Python
I have personally gotten a lot of mileage from just writing the compute heavy parts of my code in C++ and exposing it to Python with a tool like PyBind11 [1] or NumpyEigen [2]. I find tools like numba and cython to be more trouble than they're worth.

[1] https://github.com/pybind/pybind11 [2] https://github.com/fwilliams/numpyeigen

I think they should give up on Flutter for Web and just focus on mobile and desktop (and maybe extend use on Smart Watches, Smart TV, embedded instead). Too many people still remember Java Applets, google's GWT, Flash/Flex and how it ended. They are out of focus trying to support Web as well.

I had also higher expectation regarding Dart FFI - I think with their ffigen we are still only in ctypes like python bindings territory. Nowhere near something like pybind11 [0] for c++ bindings yet.

[0] https://github.com/pybind/pybind11

[1] https://github.com/mozilla/uniffi-rs

This was not my information at the time. But thanks for the info, it is helpful.

With https://github.com/pybind/pybind11 there is really great integration with C++ and Python is my second home after C++ actually.

Anyway, I am quite happy with Wren and it seems to be fast (not a requirement for my project, though)

I've been playing with PyO3 for prototyping, and wrapped some Rust code to see if it's faster than Python. The experience was very much like using Boost Python (whcih these days has alternative with https://github.com/pybind/pybind11). It's _really_ easy to wrap code for Python, and it has nice APIs to ensure GIL is held. Being Rust, I'm much more confident I won't suffer from memory unsafety issues which my C++ at the time did.

Now I'm starting to use it as part of the Python memory profiler I'm working on (https://pythonspeed.com/fil), in this case to call in to the low-level Python C API which PyO3 includes bindings for in addition to its high-level API. This kind of usage is more like writing C, except with the benefit of having high-level APIs (for GIL holding, but also object conversion) available when I need it.

So basically you get safe, high-level, easy-to-use APIs, with fallback to low-level unsafe APIs if you need them.

Highly recommend trying it out.

You can look at the pybind11 (https://github.com/pybind/pybind11) codebase. It is a library for generating python bindings for C++ code. It uses latest C++17 and does quite a lot of template metaprogramming to generate the bindings.
Amazing work! Mitsuba has long been a staple of the rendering research world, and the new architecture that Mitsuba 2 brings is nothing short of revolutionary in many aspects.

Mitubsa 2 allows for essentially writing complex path tracing code once and automatically being able to generate a traditional CPU-based scalar path tracer, an NVIDIA RTX accelerated path tracer, a vectorized path tracer, and fully differentiable path tracer, etc. A lot of the underlying heavy lifting for this capability can be found in a separate library by the same authors [1].

You may be familiar with pybind11 [1]; this is from the same author and uses pybind11 extensively. A lot of people don't know that the author of pybind11 is actually one of the top rendering researchers in the world.

There's been an enormous amount of buzz about Mitsuba 2 in the rendering world since the paper [3] came out last year. I for one am pretty excited about diving into the code.

[1] https://github.com/mitsuba-renderer/enoki [2] https://github.com/pybind/pybind11 [3] https://dl.acm.org/doi/10.1145/3355089.3356498

I think python+pybind11 solves everything. Start with python and move slower parts to C++11 using pybind11. Bonus point: You can use all the existing C/C++ libraries. https://github.com/pybind/pybind11
I’ve done a lot of interfacing with C and C++. pybind11 [0] has been the easiest and most effective for me to use. It targets C++, but it’s easy enough to wrap C code with it. Cython brings along a lot more bookkeeping code and overhead in my experience. cffi isn’t bad, but it’s not as flexible/expressive.

[0] https://github.com/pybind/pybind11

Agreed! Although I use SWIG on my job, pybind11[0] is a nice alternative that I've been looking at.

[0] https://github.com/pybind/pybind11

Most definitely not. You can write C++ extensions inside Jupyter notebook these days ([1]) -- thanks to libraries like pybind11 [2].

[1] https://github.com/aldanor/ipybind [2] https://github.com/pybind/pybind11

I can’t help mentioning my own project - https://github.com/aldanor/ipybind - which provides a lightweight Jupyter interface to pybind11 [1], allowing to quickly sketch working C++ extensions in the notebook; all features of pybind11 like numpy support are immediately available. Been using it myself quite a lot for prototyping C++/Python code.

[1] https://github.com/pybind/pybind11

I find pybind11 [1] to be perfect for my C++ code. There's so little boilerplate, and I get RAII-guaranteed memory safety and all the speed my C++ development can bring.

For example, the binding of an accelerated HyperLogLog implementation only requires tiny amount of work, plus a line in my Makefile:

  PYBIND11_MODULE(_hll, m) {
      m.doc() = "pybind11-powered HyperLogLog"; // optional module docstring
      py::class_ (m, "hll")
          .def(py::init())
          .def("clear", &hll_t::clear, "Clear all entries.")
          .def("resize", &hll_t::resize, "Change old size to a new size.")
          .def("sum", &hll_t::sum, "Add up results.")
          .def("report", &hll_t::report, "Emit estimated cardinality. Performs sum if not performed, but sum must be recalculated if further entries are added.")
          .def("add", &hll_t::add, "Add a (hashed) value to the sketch.")
          .def("addh_", &hll_t::addh, "Hash an integer value and then add that to the sketch.");
  }
[1] https://github.com/pybind/pybind11
pybind11 is the nicest foreign function interface I've encountered:

https://github.com/pybind/pybind11

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

https://github.com/pybind/pybind11

We've had good luck with some academic code bases in production -- ETH Zurich puts out some great code [1,2].

[1] https://github.com/libigl/libigl

[2] https://github.com/pybind/pybind11

If you're into both C++ and Python, I recommend pybind11 [1] - Cython is a crutch and moreover C++ is not a first class citizen in it. For reasonably large codebases Cython just doesn't scale and debugging is a total nightmare.

Disclaimer: I'm a contributor to pybind11.

[1] https://github.com/pybind/pybind11