Skip to content

bananaappletw/python-package-example

Repository files navigation

python-package-example Build Status

Collection of minimal examples of python package

Overview

Interface

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

Personal opinion

C/C++ Extension

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

Test

For the test, tox and pytest

tox create virtualenv then install the package and test.

Suitable for C/C++ Extension

distutils vs setuptools

Use setuptools instead

Releases

No releases published

Packages

No packages published