Skip to content

Instantly share code, notes, and snippets.

@alifahrri
Last active October 28, 2018 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alifahrri/05d80845720fe2d1e3dfeaaef9223e18 to your computer and use it in GitHub Desktop.
Save alifahrri/05d80845720fe2d1e3dfeaaef9223e18 to your computer and use it in GitHub Desktop.
cheatsheet for cython

setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

all *.pyx files in a folder

from distutils.core import setup
from Cython.Build import cythonize

setup(
  name = 'MyProject',
  ext_modules = cythonize(["*.pyx"]),
)

build_pyx.sh script for compile

#!/usr/bin/env bash
python setup.py build_ext --inplace

run it :

chmod +x build_pyx.sh
./buidd_pyx.sh

importing

directly using pyximport

import pyximport; pyximport.install()
import helloworld

ctypes and var

cdef int i, j, k
cdef float f, g[42], *h

tuples and list

cdef list foo = []
cdef (double, int) bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment