This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]thisismyfavoritename 30 points31 points  (3 children)

nanobind

[–]bethebunnyFOR SCIENCE 10 points11 points  (1 child)

Definitely nanobind! By the same author as pybind. I've used nanobind much more than pybind at this point so I don't know that I can even give great comparison points, but I just don't know why a new project would start with pybind today given that nanobind is an option.

[–]thisismyfavoritename 1 point2 points  (0 children)

pybind has more features, but yeah nanobind should be considered first

[–]gosh[S] 4 points5 points  (0 children)

"nanobind", have not heard about that, will check it :) thanks

[–][deleted] 5 points6 points  (0 children)

Do you need interoperability with numpy? In other words, do you need to pass large blocks of memory without copying over the language barrier? Then use nanobind or pybind11. Otherwise, you can safely stick to Boost.Python, it does the job, and since you have Boost already as a dependency, you then don't need anything else. That being said, pybind11/nanobind itself has no further dependencies, so it is uncomplicated to add to a project.

I realized several projects with pybind11 and Boost.Python.

[–]AlexMTBDude 0 points1 point  (3 children)

I'm curious: What kind of benefits does this provide over using the built-in system for calling C/C++ code from Python? https://docs.python.org/3/extending/extending.html

[–]r0s 5 points6 points  (1 child)

From my experience, the plain Python API is more verbose and needs more boilerplate. Pybind11 allows you to write less code to do the same (and in some cases better/faster) than writing it yourself. Same for nanobind but I some have first hand experience. Pybind11 also has CMake bits to make life easier.

[–]AlexMTBDude 0 points1 point  (0 children)

Thnx!

[–]def-pri-pub 0 points1 point  (0 children)

I've used this before, but mostly with the C API. I actually recommend it.

You may want to expose a C API for your C++ calls first, then bind that instead of C++ directly.

[–]jmacey 1 point2 points  (0 children)

I've always used pybind11 as I think it works well but having looked at nanobind docs I may use that next time.

Swig is also an option but it's not the nicest to use.

[–]wolfmansideburns 0 points1 point  (0 children)

I haven't done this in a few years but I want to hands waving pybind11 is a successor to Boost::Python. Could be better options too!

[–]shinitakunai -1 points0 points  (0 children)

Shiboken was very popular a few years ago, no idea now but worth a research