Let's say I have a directory "pylib" with this in it:
pylab/funcs.py:
def add(a, b): return a + b pylab/__init__.py:
from .funcs import add It is then possible to do the following:
$ python -c "import pylib as lib; print(lib.add(5, 6))" 11 How can I achieve the same effect with Cython with a similar organizational structure? That is, if I just have a single file, like:
cylab.pyx:
def add(a, b): return a + b I can create a setup script
setup.py:
from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize extensions = [ # I will eventually be referencing C libraries Extension('cylib', ['cylib.pyx'], libraries=[], library_dirs=[]) ] setup( ext_modules = cythonize(extensions) ) and then the rest works in a fairly straightforward way
$ ./setup.py build_ext --inplace [omitted] $ python -c "import cylib as lib; print(lib.add(5, 6))" 11 but it is not clear to me how I'm supposed to break it up into separate files, nor how I'm supposed to modify the setup script once I do.