# Basics [Cython]¶

Basic functions and operations using Cython and Python.

# 0. Installation¶

Installation command for anaconda and pip:

$conda install -c anaconda cython or $ pip install Cython

# 1. Compilation¶

A Cython source file has the name of the module followed by the extension .pyx. For example, given the source file examples_cy.pyx with a simple function which returns a string.

def hello_cython():
return 'Hello, Cython!'


The following step consist of creating the setup.py, which will be responsible for the compilation process.

from setuptools import setup
from Cython.Build import cythonize

setup(
name="Examples Cython",
ext_modules=cythonize("examples_cy.pyx")
)


Given that, the compilation step is done by running the command:

# 3. Cython and Jupyter Notebook¶

To enable support for Cython compilation in Jupyter Notebooks, we have to run firstly the command:

It will allow the C functions declaration inside cells, using the magic function %%cython for multiple lines.

p.s.: the function call must be within the same cell