Basic Cython
Getting Started
First you'll need to install Cython. This is typically as easy as running pip install cython. You'll also need Python of course, with header files, and a C compiler. For more details, see http://docs.cython.org/src/quickstart/install.html. You then compile your code by writing a setup.py file.
Alternatively, you can try Cython out online via the http://cloud.sagemath.org.
My first Cython program
##What is Cython?
Cython is an optimizing Python-to-C compiler
Cython code is turned into C code which is compiled and loaded into a running Python session
You can easily call Python code from Cython and Cython code from Python
Cython is an extenstion of the Python language
Extra syntax for declaring types and other constructs
Cython is the easiest way to write Python C extensions
No need to learn, or port to, new language
No dealing with ref counting, argument parsing, type conversion, exception handling...

Why Cython
Optimize only what you need
Most time is spent in a small portion of your code
Easy migration
Of both code and developers
Piece by piece as needed
Focus on the algorithm
...not the boring, tedious, and error-prone boilerplate code
Leverage everything from the Python ecosystem

What makes Python slow
It's interpreted
Cython is compiled
Everything is an object
Cython has primitive cdef types
Complicated calling conventions
Cython has cdef functions
Dictionary lookups
Cython has cdef attributes
Let's see these used in practice. First, define a simple integral in Python.
Now compile this same exact code with Cython.
A 2x speedup. Not bad, but we can do much better. We can declare function arguments and local variables as C types using the cdef keyword.
A significant source of overhead is Python function calls. Let's make f into a cdef function.
Of course we don't want to be stuck with a single function, let's make a class that allows you to customize this function.
Cython is also often used to call external libraries using the extern keyword.
One can also cimport functions and classes from other Cython files, both built-in and from other packages.
Working with NumPy
As Cython is often used in a numerical/scientific computing context, it has extensive support for working with Numpy arrays. There are two interfaces: the buffer syntax and the memory view syntax. Below is just a the basic sample, for more see http://docs.cython.org/src/tutorial/numpy.html and http://docs.cython.org/src/userguide/memoryviews.html
Generally, when shipping a project using Cython, one puts Cython modules in .pyx files along side .py files and uses a setup.py file:
You can also use decorators to compile things "just in time."
Compiled code is cached for re-use.
We can also use the cython.compile decorator.
These caches are specialized and cached per type.
Compiled code is cached for re-use.