Skip to content

Python Support

Python support in Djinni is experimental, but ready to try out. It can generate code for bridging C++ with Python 3.

For more information, you can check out the talk from CppCon 2015. Slides and video are avilable online.


Djinni generates code which should work with Python 3. Python support has only been tested on macOS with the clang compiler. ~~It's been designed to work on any platform, and the known issues are in the build scripts rather than the generated code itself.~~ (We're now using CMake to build all bindings but it still requires testing in platforms other than macOS.)

The Python support generated by Djinni makes use of a few non-default Python extensions, as does the test suite. You can install them as follows:

  sudo pip3 install cffi
  sudo pip3 install future
  sudo pip3 install pytest

Test Suite

Because of the known limitations described below, the Python test suite does not use all of the same inputs as the other languages. As a result, you'll see a separate pycpp directory in generated-src. This contains output of the standard C++ generator, but for the specific input files used by the Python test suite.

Known limitations

  • Proxy caching is not yet implemented. In addition to some inefficiency, this means that the same object passed across the language boundary twice is not guaranteed to appear as a single object on the other side.
  • The support library code makes direct reference to types rather than respecting the command-line choice of a different optional library.

Python support on Windows not complete yet

If you want help development of that feature, please download the current generator for Windows and place it in the root folder.

Generate the cmake project:

cmake -S . -B build/py -DDJINNI_WITH_PYTHON=ON -DDJINNI_EXECUTABLE="$(((Get-Location).Path) -replace "\\","/")/djinni.bat" -G "Visual Studio 16 2019"

Run the build

cmake --build build/py

Explore the error. Help will be welcome!

Last update: July 5, 2021