The Cython language makes writing C extensions for the Python language as easy as Python itself. Cython is a source code translator based on Pyrex_, but supports more cutting edge functionality and optimizations.
The Cython language is a superset of the Python language (almost all Python code is also valid Cython code), but Cython additionally supports optional static typing to natively call C functions, operate with C++ classes and declare fast C types on variables and class attributes. This allows the compiler to generate very efficient C code from Cython code.
This makes Cython the ideal language for writing glue code for external C/C++ libraries, and for fast C modules that speed up the execution of Python code.
The newest Cython release can always be downloaded from https://cython.org/. Unpack the tarball or zip file, enter the directory, and then run::
pip install .
Note that for one-time builds, e.g. for CI/testing, on platforms that are not covered by one of the wheel packages provided on PyPI and the pure Python wheel that we provide is not used, it is substantially faster than a full source build to install an uncompiled (slower) version of Cython with::
NO_CYTHON_COMPILE=true pip install .
.. _Pyrex: https://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
Builtin exception types are now inferred. (Github issue https://github.com/cython/cython/issues/6908)
Item type inference was improved for looping over literals. (Github issue https://github.com/cython/cython/issues/6912)
Looping over literal sequences and strings now uses efficient C array looping if possible. (Github issue https://github.com/cython/cython/issues/6926)
Using NaN
as exception return value is supported.
(Github issues https://github.com/cython/cython/issues/6900, https://github.com/cython/cython/issues/6903)
Special float exception values could generate invalid C code. (Github issues https://github.com/cython/cython/issues/6900, https://github.com/cython/cython/issues/6903)
References to the Python bool
type could generate invalid C code.
(Github issue https://github.com/cython/cython/issues/6902)
Pure mode type alias like p_int
or ulong
leaked into some C type contexts.
(Github issues https://github.com/cython/cython/issues/6922, https://github.com/cython/cython/issues/6339)
Vectorcalls could use needless temp assignments for self
.
(Github issue https://github.com/cython/cython/issues/6909)
Includes all fixes as of Cython 3.1.2.
3.1.2 (2025-??-??):
Attribute lookups failed on the bool
builtin type.
(Github issue https://github.com/cython/cython/issues/6905)
Iterating over literal sequences with starred (unpacked) items could infer a wrong type for the loop variable and fail to assign the values. (Github issue https://github.com/cython/cython/issues/6924)
Avoid including C++11 <type_traits>
unconditionally.
(Github issue https://github.com/cython/cython/issues/6896)
PyDict_GetItemStringRef()
was accidentally used in older Limited API versions.
(Github issue https://github.com/cython/cython/issues/6914)
abort()
was used but not always available in the Limited API.
(Github issue https://github.com/cython/cython/issues/6918)
Embedded function signatures were not always separated from the existing docstring. (Github issue https://github.com/cython/cython/issues/6904)
Some tests were adapted for NumPy 2.x. (Github issue https://github.com/cython/cython/issues/6898)
Some C compiler warnings were fixed. (Github issue https://github.com/cython/cython/issues/6870)