Developer(s) | Robert Bradshaw, Stefan Behnel, et al. |
---|---|
Initial release | 28 July 2007 |
Stable release | 0.25.2 (8 December 2016 | )
Written in | Python, C |
Operating system | Cross-platform |
Type | Programming language |
License | Apache License |
Website | cython |
Cython is a superset of the Python programming language, designed to give C-like performance with code which is mostly written in Python.
Cython is a compiled language that generates CPython extension modules. These extension modules can then be loaded and used by regular Python code using the import statement.
Cython is written in Python and works on Windows, Linux, and macOS, producing source files compatible with CPython 2.4 through 3.5.
Cython works by producing a standard Python module. However, the behavior differs from standard Python in that the module code, originally written in Python, is translated into C. While the resulting code is fast, it makes many calls into the CPython interpreter and CPython standard libraries to perform actual work. Choosing this arrangement saved considerably on Cython's development time, but modules have a dependency on the Python interpreter and standard library.
Although most of the code is C-based, a small stub loader written in interpreted Python is usually required (unless the goal is to create a loader written entirely in C, which may involve work with the undocumented internals of CPython). However, this is not a major problem due to the presence of the Python interpreter.
Cython has a foreign function interface for invoking C/C++ routines and the ability to declare the static type of subroutine parameters and results, local variables, and class attributes.
A Cython program that implements the same algorithm as a corresponding Python program may consume fewer computing resources such as core memory and processing cycles due to differences between the CPython and Cython execution models. A basic Python program is loaded and executed by the CPython virtual machine, so both the runtime and the program itself consume computing resources. A Cython program is compiled to C code, which is further compiled to machine code, so the virtual machine is used only briefly when the program is loaded.