Collection of minimal examples of python package
All the examples provide Person class with instance method hello()
class Person:
def hello(self):
return 'hello'
from xxx_package import Person
Person().hello()
pure python implementation
pure cpp implementation package is compiled into single .so file
pure python implementation package is compiled into single .so file
pure cpp implementation package is compiled into single .so file
I perfer Cython to other implementations
It's more flexible than swig
swig currently have limited C++11 standard support
For example, smart pointer
Only shared_ptr supported
Besides, there is a slight difference between c++ and python
For example, you want to access property name
from Person class
Cython
use C++ getter to access private member and encapsulated as Python property
cdef class Person:
cdef CPPPerson *thisptr
def __cinit__(self):
self.thisptr = new CPPPerson()
@property
def name(self):
return self.thisptr.getName().decode()
Swig
interface directly inherit from c++ class, need to do something nasty
tox create virtualenv then install the package and test.
Suitable for C/C++ Extension
Use setuptools instead