Cython 3 Released
Written by Mike James   
Tuesday, 18 July 2023

Cython 3.0, the latest release of the Python library that can be used to compile Python code to C, has been released with improvements including support for recent versions of Python, easier working with NumPy, and reworking to support Python's 'limited' API.

Cython is a Python implemenation that makes writing C extensions for Python as easy as Python itself. It is based on
Pyrex, but supports more cutting edge functionality and
optimizations. The Cython language is very close to the Python language, but Cython additionally supports calling C functions and declaring C types on variables and class attributes. This allows the compiler to generate very efficient C code from Cython code.

The developers say that Cython 3.0.0 has been a very large effort that cleaned up many old warts, introduced many new features, and introduces a couple of intentional behavior changes, even though the goal remained to stay compatible as much as possible with Cython 0.29.x.

Cythpnbanner

Retaining compatibility with Python is a major part of the update, as CPython versions 3.8-3.11 were released while Cython 3 was under development. All these versions are supported in Cython, including experimental support for the in-development CPython 3.12.

Cython interacts very closely with the C-API of Python, and this is where most of the adaptation work happens, according to the developers. Work has also been carried out so that Cython can parse newer Python constructs for use with its pure python mode.

The new release has also added support for non-ASCII identifiers so that developers writing in a language that uses non-ASCII letters can use them in identifiers. It also has simplified customisation of class creation to avoid the need to use a custom metaclass. Other improvements include support for positional-only parameters and for assignment expressions (a.k.a. the walrus operator :=).

Initial support has been added for CPython's so-called Limited API. This is a stable, limited subset of CPython's C-API that comes with the guarantee of a stable ABI, meaning that extensions modules that were compiled for one version of CPython can also be imported in later versions without recompilation.

There is now initial support for this in Cython with an option to cut down on Cython's C-API usage to adhere to the Limited C-API. The developers say some advanced Python features (like async code) may lead to C code that cannot adhere to the Limited C-API, or where Cython simply does not know yet how to adhere to it.

NumPy support has also been improved so that you can write NumPy ufuncs directly in Cython.

Cython 3 is available now.

Cythpnicon

  • Mike James is the author of the Programmer's Python  triology of books. Subtitled "Something Completely Different" this series for those who want to understand the deeper logic in the approach that Python 3 takes to classes and objects, data and asynchronous programming. He has also collaborated with Harry Fairhead on titles covering the Raspberry Pi, Raspberry Pi Pico and most recently the ESP32 using Micropython. He is currently working on Extending Python Using C a deep dive into C extensions.

 

More Information

Cython Website

Cython On GitHub

Related Articles

Cython is 20 - Why Is It Ignored?

Pyston To Merge With CPython?

Guido And Microsoft Want To Make Python x2 Faster

Pyston 2.2 Goes Open Source Again

Too Much Py In PyPI

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


JetBrains Improves Kubernetes Support In IDE Upgrades
12/11/2024

JetBrains has improved its IDEs with features to suggest the logical structure of code, to streamline the debugging experience for Kubernetes applications, and provide comprehensive cluster-wide Kuber [ ... ]



Microsoft Introduces Vector Abstractions Library For .NET
21/11/2024

Microsoft has announced a preview release of the Microsoft Extensions VectorData Abstractions library, which can be used to help integrate vector stores into .NET applications and libraries.


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:1871962749>

<ASIN:1871962757>

<ASIN:1871962765>

<ASIN:187196282X>

Last Updated ( Tuesday, 18 July 2023 )