The commonly used Python interpreter (CPython implementation) has a nice C API that you can use to interface with your C/C++ code. You can manually write the code for this interface, or use the SWIG toolkit to get the job done. This code will be compiled to a dynamic library - called a Python C extension.
However, if you use another interpreter (like PyPy), you can run into problems, because Python C extensions are incompatible with most other interpreters. In this way a lot of libraries will become unusable. Here Wrappyr comes in, to take most of the pain away.
The Wrappyr project will extract API information about a C/C++ library, generate a C interface if needed and finally generate Ctypes based Python code which serves as an interface between the C code and your Python application. In this way, Wrappyr enables you to use C/C++ libraries with just about any Python implementation.
The Wrappyr project is a collection of tools, composed of the following three parts:
- The Wrappyr project takes advantage of the Clang C/C++ compiler, to extract and export information about the C/C++ code.
A Clang plugin dumps classes, functions, etc. from a header file to XML.
- A tool that imports the XML file produced by the Clang plugin and does two things:
- Generate a C API for your C++ code.
- Generate an XML file describing how the Python API should look, which C calls should be made where, etc.
- A tool that creates the Ctypes-based Python API from an XML file.
Would you like to learn (more about) Python? Have a look at our Dutch or English language Python training which we provide in European countries...