Installation and use with setuptools

Since Cppy is nothing else than a collection of header that are only compiled when used, installing it is extremely straightforward using pip:

$ pip install cppy

If you want to run the development version, you can install directly from GitHub:

$ pip install

Using Cppy in an extensions

To use Cppy in your extension (written in C++), you simply need to include it.

#include <cppy/cppy.h>

Cppy includes Python.h so when including cppy.h you do not need to also include Python.h.

Every functions, classes exposed by Cppy are stored in the cppy namespace.

cppy::ptr obj_ptr( PyUnicode_FromString("test") )

Use with setuptools

Cppy is only needed during the installation step of the projects using it. The following example script illustrates how to use Cppy without requiring it to be installed before is run.

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext

ext_modules = [

class BuildExt(build_ext):

    def build_extensions(self):

        # Delayed import of cppy to let setup_requires install it if
        # necessary
        import cppy

        ct = self.compiler.compiler_type
        for ext in self.extensions:
            # cppy.get_include() collect the path of the header files
            ext.include_dirs.insert(0, cppy.get_include())

    cmdclass={'build_ext': BuildExt},