Some, but not all, functions of the CGAL library have already Python bindings. Here an example is provided for a case without such a binding and how it might be implemented. The example is taken from the CGAL Documentation.

One can also handle more complex data, e.g. Python objects like lists. The attributes are accessed with the extract function executed on the objects "attr" function output. We can also throw errors by telling the library that an error has occurred and returning. In the following case, we have written a C++ function called "afunction" which we want to call. The function takes an integer N and a vector of length N as input, we have to convert the python list to a vector of strings before calling the function.

#include<vector>usingnamespacestd;void_afunction_wrapper(intN,boost::python::listmapping){intmapping_length=boost::python::extract<int>(mapping.attr("__len__")());//Do Error checking, the mapping needs to be at least as long as N if(mapping_length<N){PyErr_SetString(PyExc_ValueError,"The string mapping must be at least of length N");boost::python::throw_error_already_set();return;}vector<string>mystrings(mapping_length);for(inti=0;i<mapping_length;i++){mystrings[i]=boost::python::extract<charconst*>(mapping[i]);}//now call our C++ function_afunction(N,mystrings);}usingnamespaceboost::python;BOOST_PYTHON_MODULE(c_afunction){def("afunction",_afunction_wrapper);}