Async Techniques and Examples in Python Transcripts
Chapter: Parallelism in C with Cython
Lecture: Concept: Getting started with Cython

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's quickly review how we can use Cython
0:02 to write native code, and then import it
0:04 and run it in Python.
0:06 So, all we have to do is create a pyx file
0:09 this is the Cython extension by default
0:12 and then we write standard Python code.
0:15 It could be plain Python, like we have here in this top box
0:19 or it could be specialized code
0:20 like I showed you in the example
0:22 where it talks about the types in terms of
0:24 native Cython types and so on.
0:25 And then we have to have a setup file
0:27 so we import setup and we import cythonize
0:30 and then we just call setup
0:32 and set the ext_modules to include that one
0:34 that we're working in above
0:36 and then we just make sure we have Cython installed.
0:39 So pip install cython, and then we run Python
0:42 setup.py build_ext --inplace.
0:45 That builds it, out pops a high dot platform name
0:50 version name, et cetera, .so or depending on what platform
0:53 of Git your on, you might get a different output there.
0:55 And then you can just import high
0:58 like you could any other module
0:59 as if that was a Python file itself
1:02 except for, now it's running native C code
1:05 that's been compiled by being translated
1:07 with Cython from Python into C.
1:10 Pretty awesome.