Skip to main content

Distribute python modules/packages as binary files (compilation based on Cython)

Project description

setuptools-cythonize

Python 2.7+/3.5+ PyPi package PyPi downloads

The setuptools-cythonize provides distutils classes to compile Python source code into C code using Cython. The generated code is packaged into a platform dependent archive.

cythonization

Install

$> pip install setuptools-cythonize

Setup configuration

Add the cmdclass keyword to the setup:

from setuptools import setup
from setuptools_cythonize import get_cmdclass

setup(
    cmdclass=get_cmdclass(),
    name="my_package",
    version="2.0.5",
    description="My custom library",
    ...
)

Note

the function get_cmdclass() force wheel as default format (recommended format for binary distribution). This behavior can be disabled by passing the parameter wheel_default=False.

Some packages can be excluded from the cythonization by setting the exclude_cythonize option. The module names matching is done using the function fnmatch.fnmatchcase .

from setuptools import setup
from setuptools_cythonize import get_cmdclass

setup(
    cmdclass=get_cmdclass(),
    name="my_package",
    ...
    options={
        'build_py':
            {'exclude_cythonize': ['my_package.subpack*']}
    },
    ...
)

Note

some Python modules starting with __ are excluded from the cythonization. This includes:

  • the __init__.py files which are mandatory to keep the Python packages integrity
  • the __main__.py file in order to exectute the package using the command python -m ...

The Cython compiler options can also be customized before running the setup:

from setuptools import setup

from Cython.Compiler import Options

Options.docstrings = False

setup(
    ...
)

Packaging

Generate your package by executing the setup.py file, all Python modules (except the ones defined in exclude_cythonize) will be compiled and packaged:

$> python setup.py bdist --cythonize

A source package can still be generated by removing the --cythonize option:

$> python setup.py bdist

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for setuptools-cythonize, version 1.0.6
Filename, size File type Python version Upload date Hashes
Filename, size setuptools_cythonize-1.0.6-py2.py3-none-any.whl (5.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size setuptools-cythonize-1.0.6.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page