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",
    ...
)

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*']}
    },
    ...
)

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(
    ...
)

To speedup files compilation, the cythonization can be performed in parallel by setting the parallel option. The number of CPUs availbale can be retrived using the multiprocessing module. For instance:

import multiprocessing
from setuptools import setup
from setuptools_cythonize import get_cmdclass

setup(
    cmdclass=get_cmdclass(),
    name="my_package",
    ...
    options={
        'build_ext':
            {'parallel': multiprocessing.cpu_count()}
    },
    ...
)

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.

Source Distribution

setuptools-cythonize-1.0.7.tar.gz (5.5 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page