The Cython Compiler for C-Extensions in Python

Dr. Stefan Behnel

About myself

What is Cython?

Cython is

A little bit of history

Major Cython Developers

How to use Cython

Example: compiling Python code

$ cat
class HardWorker(object):
    u"Almost Sisyphus"
    def __init__(self, task):
        self.task = task

    def work_hard(self):
        for i in range(100):
$ cython

Portable Code

... the fastest way to port Python 2 code to Py3 ;-)

Python 2 feature support


Cython generates very efficient C code

Type declarations

Why is this stupid?

Ask Cython!

$ cat
def stupid_lower_case(char* s):
    cdef Py_ssize_t size, i

    size = len(s)
    for i in range(size):
        if s[i] >= 'A' and s[i] <= 'Z':
            s[i] += 'a' - 'A'
    return s
$ cython --annotate

=> stupidlowercase.html

Calling C functions

Features in work

Huge pile of great ideas


... but Cython is also



C-Extensions in Python

... use it, and join the project!