cython
Compile Cython code to C
TLDR
Compile into C code
Compile into C++ code
Specify an output file
Display version
SYNOPSIS
cython [options] source_file.pyx
PARAMETERS
-a, --annotate
Generate annotated HTML showing code lines and C code generation
-b, --no-docstrings
Strip docstrings from generated C code
-I DIR, --include-dir DIR
Add directory to include search path
-o FILE, --output-file FILE
Specify C output filename (default: <input>.c)
-i, --inplace
Replace input .pyx with generated .c file
-v, --verbose
Print verbose progress information
-w DIR, --work-dir DIR
Set working directory for output files
-V, --version
Display Cython version and exit
--help, -?
Show help message and exit
-2
Use Python 2 source semantics
-3
Use Python 3 source semantics (default)
-X specs, --directive specs
Set compiler directives (e.g., language_level=3)
-D macro[=value], --define macro[=value]
Define C preprocessor macro
--line-directives
Emit #line directives in output
-t, --timestamp
Include file timestamp in function signatures
DESCRIPTION
The cython command is the primary compiler for Cython, a programming language that extends Python with C-like syntax for high-performance code. It translates .pyx source files—supersets of Python—into C code suitable for compilation into Python extension modules.
Cython enables static typing, direct memory access, and calls to C/C++ libraries, achieving speeds close to native C while retaining Python's ease. The command processes input files, generating .c files with embedded Python API calls. Use it in build workflows with setuptools or distutils to create shared libraries (.so on Linux).
Key features include optional HTML annotations for type tracking, directive overrides for compiler behavior, and preprocessor macro definitions. It's essential for numerical computing, machine learning, and performance-critical Python apps, often integrated via cythonize scripts.
CAVEATS
Requires Cython package installed (e.g., pip install cython); generated C code must be compiled separately with gcc and Python headers; not for pure Python scripts.
TYPICAL WORKFLOW
1. Write hello.pyx
2. cython hello.pyx → hello.c
3. Use setup.py: from setuptools import setup; setup(ext_modules=cythonize('hello.pyx'))
4. python setup.py build_ext --inplace
INSTALLATION
pip install cython or apt install cython3 on Debian-based systems.
HISTORY
Originated from Pyrex (2002 by Greg Ewing); renamed Cython in 2007 under Stefan Behnel and others; major releases align with Python versions, with v3.0+ supporting Python 3 exclusively.


