About Anaconda Help Download Anaconda
  • 241994 total downloads
  • Last upload: 11 hours and 28 minutes ago

Installers

pip install

To install this package run one of the following:
pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple cython

Description

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/

3.2.0a0 (2025-??-??)

Features added

  • Builtin exception types are now inferred. (Github issue https://github.com/cython/cython/issues/6908)

  • The list of known, inferred and optimised Python builtins was updated. range is now considered a type. ascii, bin, format, hex, oct were added as functions. (Github issue https://github.com/cython/cython/issues/6931)

  • The f-string syntax was extended according to PEP-701. (Github issue https://github.com/cython/cython/issues/5452)

  • The runtime Python dispatch for fused functions is substantially faster. (Github issues https://github.com/cython/cython/issues/1385, https://github.com/cython/cython/issues/6996)

  • Freelists (via cdef class decorator and for internally used types such as async) are now also used in the Limited API and with extension type specs enabled. (Github issue https://github.com/cython/cython/issues/7151)

  • Module imports now quickly check for an already imported module to speed up reimports. Patch by Lysandros Nikolaou. (Github issue https://github.com/cython/cython/issues/7035)

  • Type checks on PEP-604 union types (int | None) are optimised into separate checks. (Github issue https://github.com/cython/cython/issues/6935)

  • Assignments to the PEP-604 union type float | None allow any suitable Python number as input and convert it to a Python float automatically. (Github issue https://github.com/cython/cython/issues/5750)

  • 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)

  • Releasing the GIL from an unknown lock state is more efficient. (Github issue https://github.com/cython/cython/issues/6847)

  • cython.critical_section(PyMutex) now works, as with Python objects. (Github issue https://github.com/cython/cython/issues/6847)

  • bool(c_int/float/ptr) avoid passing through Python objects. (Github issue https://github.com/cython/cython/issues/7015)

  • Unused exceptions in except clauses are detected in some more cases to avoid their normalisation. (Github issue https://github.com/cython/cython/issues/7021)

  • Some object constants are now marked as immortal to speed up their reference counting in recent CPython versions. This can be configured with the CYTHON_IMMORTAL_CONSTANTS C macro. (Github issue https://github.com/cython/cython/issues/7118)

  • Several improvements were made in freethreaded Python code. (Github issues https://github.com/cython/cython/issues/6936, https://github.com/cython/cython/issues/6939, https://github.com/cython/cython/issues/6949, https://github.com/cython/cython/issues/6984, https://github.com/cython/cython/issues/7011, https://github.com/cython/cython/issues/7114)

  • Several improvements were made for the Limited API. (Github issues https://github.com/cython/cython/issues/6959, https://github.com/cython/cython/issues/6991)

  • Some GIL-safe C-API wrappers were added to the libc/libcpp declarations. (Github issue https://github.com/cython/cython/issues/6829)

  • String and number constants use less storage space in the module. (Github issues https://github.com/cython/cython/issues/6971, https://github.com/cython/cython/issues/6978, https://github.com/cython/cython/issues/6986)

  • The managed dict/weakref support in CPython 3.12+ is used for internal types to benefit from future CPython optimisations here. (Github issue https://github.com/cython/cython/issues/6891)

  • Using NaN as exception return value is supported. (Github issues https://github.com/cython/cython/issues/6900, https://github.com/cython/cython/issues/6903)

  • Declarations for C++ condition variables were added. (Github issue https://github.com/cython/cython/issues/6836)

  • Several improvements were made for the GraalPython support. Patch by Michael Šimáček. (Github issue https://github.com/cython/cython/issues/7074)

  • The annotated source HTML page shows alternating +/− markers to open/close lines. Patch by Kamil Monicz. (Github issue https://github.com/cython/cython/issues/7099)

  • Unicode 16.0.0 is used to parse identifiers. (Github issue https://github.com/cython/cython/issues/6836)

Bugs fixed

  • 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)

  • Vectorcalls could use needless temp assignments for self. (Github issue https://github.com/cython/cython/issues/6909)

  • Iterating over temporary memoryviews could crash Cython. (Github issue https://github.com/cython/cython/issues/7005)

  • Type casts on constants as part of numeric expressions could crash Cython. (Github issue https://github.com/cython/cython/issues/6779)

  • Long code bodies in with statements could crash Cython. (Github issue https://github.com/cython/cython/issues/7122)

  • Indexing bytes failed to optimise in some cases. (Github issue https://github.com/cython/cython/issues/6997)

  • The type objects of heap types were not always correctly decrefed on deallocation. (Github issue https://github.com/cython/cython/issues/7145)

  • Pure mode type aliases like p_int or ulong leaked into some C type contexts, risking to conflict with user declarations. (Github issues https://github.com/cython/cython/issues/6922, https://github.com/cython/cython/issues/6339)

  • Boolean (emptyness) tests on builtin containers could fail to handle (unlikely) errors. (Github issue https://github.com/cython/cython/issues/7090)

  • The return type of bytes.join() was sometimes referred as plain object. (Github issue https://github.com/cython/cython/issues/6987)

  • Type inference could fail to understand prange() arguments. (Github issue https://github.com/cython/cython/issues/6974)

  • embedsignatures failed if lambda was used in function default arguments. (Github issue https://github.com/cython/cython/issues/6880)

  • An internal C function was not marked as static and leaked a linker symbol. (Github issue https://github.com/cython/cython/issues/6957)

  • Cython's tools and frontend scripts now use python3 instead of just python in their shebang line. Patch by Matti Picus. (Github issue https://github.com/cython/cython/issues/7053)

  • Includes all fixes as of Cython 3.1.4.

3.1.4 (2025-09-16):

  • The monitoring code could crash on tracing. (Github issue https://github.com/cython/cython/issues/7050)

  • Initialising the monitoring code could fail with a CPython exception. See https://github.com/nedbat/coveragepy/issues/1790#issuecomment-3257410149

  • Optimised integer shifting triggered undefined behaviour in C. (Github issue https://github.com/cython/cython/issues/7089)

  • Deallocating objects that inherit from external types defined in pxd files could run into an infinite loop. (Github issue https://github.com/cython/cython/issues/7143)

  • A reference to metaclasses could be leaked on instantiation. (Github issue https://github.com/cython/cython/issues/7130)

  • (Unlikely) error handling during empty builtin container tests was ineffective. (Github issue https://github.com/cython/cython/issues/7190)

  • Generated *_api.h files used potentially unknown Cython configuration macros. (Github issue https://github.com/cython/cython/issues/7108)

  • cythonize() avoids parallel compiler runs on systems using spawn() in multiprocessing. Patch by Marcel Bargull. (Github issue https://github.com/cython/cython/issues/3262)

  • The @cython.ufunc decorator was missing in type checker stubs. Patch by jayClean. (Github issue https://github.com/cython/cython/issues/7109)


© 2025 Anaconda, Inc. All Rights Reserved. (v4.2.2) Legal | Privacy Policy