Question

First, if i have a project that is all python (no C++ or C) files, what is the advantage of using Cython, vs, say, using the python library directly (for integration in a large C++ software program) ?

Second, to compile the .pyx files to Cython, i intend to use setup.py file with this code:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize(MyString)
)

What should MyString be ? the name of the python (.pyx) files without extension ? should it include a full path ? where should be located the setup.py file so that it cythonizes the files ? If not this way, how to properly Cythonize the files ?

  • What is the proper way to use Cython when dealing with a library containing only .py files ?

  • How to use the setup.py to cythonize (see more detailled questions above) ?

Was it helpful?

Solution

Hum there is a lot of question here.

  1. what is the advantage of using Cython, vs, say, using the python library directly ?

    If you only use Python library (eg: for network stuff), using Cython should not be of great help. Cython will greatly help you if:

    • you need access to external C/C++ library;
    • or you need to build your own fast data structure possibly using C/C++ allocation;
    • or you have an intensive number crunching application.
  2. What should MyString be ?

    They are a lot of option here. I usually use

    setup(
        cmdclass = {'build_ext': build_ext},
        ext_modules = [Extension("myext", ["myext.pyx", "myextlib.pyx"])])
    

    You'll find a lot of information at Cython compilation documentation For a small library, you can put it in the same directory as the source.

OTHER TIPS

might give you better performance gains more quickly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top