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 to write native code, and then import it and run it in Python. So, all we have to do is create a pyx file
0:10 this is the Cython extension by default and then we write standard Python code. It could be plain Python, like we have here in this top box
0:20 or it could be specialized code like I showed you in the example where it talks about the types in terms of native Cython types and so on.
0:26 And then we have to have a setup file so we import setup and we import cythonize and then we just call setup
0:33 and set the ext_modules to include that one that we're working in above and then we just make sure we have Cython installed.
0:40 So pip install cython, and then we run Python setup.py build_ext --inplace. That builds it, out pops a high dot platform name
0:51 version name, et cetera, .so or depending on what platform of Git your on, you might get a different output there. And then you can just import high
0:59 like you could any other module as if that was a Python file itself except for, now it's running native C code that's been compiled by being translated
1:08 with Cython from Python into C. Pretty awesome.


Talk Python's Mastodon Michael Kennedy's Mastodon