logo

Magicbind, automatically build Python extension modules from C++

Posted by robomei |2 hours ago |1 comments

robomei 2 hours ago

I found it annoying to set up a build system and write binding code, when I just wanted to speed up a few Python functions with C++ code. Magicbind automatically parses your C++ header with libclang, generates nanobind bindings and compiles it with either your system compiler (g++, clang, msvc) or with an integrated zig c++ compiler that is shipped with ziglang Python package. So it always works out of the box without any dependencies.

Essentially you just have to add magicbind Python package, call "magicbind add mylib.h" and you can directly import and use mylib in your Python code.

It supports most of the STL type conversions out of the box and also supports conversion from OpenCV types (cv::Mat, cv::Rect, ..). You can also use it directly from a Jupyter notebook. You can try it out in Colab: https://colab.research.google.com/github/robomei/magicbind/b...