You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.3 KiB


An IPython kernel magic library. After import pybindmagic you can use the cell magic %%cpp

In this cell you can write cpp code.


  • pybind11
  • git
  • gcc
  • cmake (optional)


pip install git+


  • add options for cmake flags
  • add other compilers
  • Better exception handling
    • Better debugging output



You need to specify all functions or classes you want to expose to python. Either by %%cpp -f funcname or by pybind11 syntax at the end of the cell. There is a shortcut by inserting a defs in the end of the cell that will add the correct module name. For an example take a look at the example notebook.


Currently only gcc is supported. The default compiler command is c++. You can change the compiler command with: pybindmagic.compiler_cmd = "gcc"


With %%cpp -c path/to/folder/with/CMakeList.txt/in you can specify cmake compilation. After evaluation pybind11 will be downloaded and moved to this folder, a build folder is generated and the cell is compiled in this folder. Makesure that you add pybind11 to your cmake file.


With the %cpp -rebuild flag you can enforce a complete rebuild.