Thursday 9 a.m.–12:30 p.m.

Get native with Cython

Stefan Behnel

Audience level:
Intermediate

Description

Cython is not only an excellent and widely used tool to speed up computational Python code, it’s also a very comfortable way to talk to native code and libraries. This tutorial by a Cython core developer introduces the Cython programming language and its compiler and leads the participants all the way from their first Python extension to an efficient integration with native C/C++ code.

Abstract

Cython is not only an excellent and widely used tool to speed up computational Python code, it’s also a very comfortable way to talk to native code and libraries. The Cython compiler translates Python code to C or C++ code, and supports static type annotations to allow direct use of C/C++ data types and functions. The tight integration of all three languages makes it possible to freely mix Python features like generators and comprehensions with C/C++ features like native data types, pointer arithmetic or manually tuned memory management in the same code.

This tutorial by a Cython core developer introduces the Cython programming language and its compiler and leads the participants all the way from their first Python extension to an efficient integration with native C/C++ code.

Topics covered will be

  • using the Cython compiler to build a native extension module
  • mixing Python with static C/C++ types in the Cython language
  • calling into native code from Cython code

Note that participants are expected to have a good understanding of the Python language, some basic knowledge about C or C++, and are able to use a C compiler on their computers to build native CPython modules from sources (e.g. install source packages from PyPI that contain C extensions). No deep C programming knowledge is required, nor is any prior knowledge needed about writing extension modules for the CPython runtime. The Cython compiler handles most of these low-level issues itself.

Sponsors