The Cython Compiler for C-Extensions in Python

Dr. Stefan Behnel

http://www.cython.org/

cython-dev@codespeak.net

About myself

What is Cython?

Cython is

A little bit of history

Major Cython Developers

How to use Cython

Example: compiling Python code

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

    def work_hard(self):
        for i in range(100):
            self.task()
$ cython worker.py

Portable Code

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

Python 2 feature support

Speed

Cython generates very efficient C code

Type declarations

Why is this stupid?

Ask Cython!

$ cat stupidlowercase.py
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.py

=> stupidlowercase.html

Calling C functions

Features in work

Huge pile of great ideas

Conclusion

... but Cython is also

Cython

Cython

C-Extensions in Python

... use it, and join the project!

http://cython.org/