Cython support
Prerequisites
PyCharm provides initial Cython support out of the box. PyCharm recognizes .pyx, .pxd, and .pxi files, and allows you to edit them. You can also compile these files into .so files on Unix and macOS or .pyd files on Windows using the Cython package.
Cython support
Cython files are marked with the icon.
Cython support includes:
Coding assistance:
Error and syntax highlighting.
Code completion for keywords, fields of structs, and attributes of extension types.
Code formatting and folding.
Ability to create line comments Ctrl+/.
Cython syntax for typed memoryviews.
Cython type checker.
Code inspections. Almost all Python code inspections work for Cython.
Smart search through the source code, in particular, finding usages.
Compiling Cython modules:
Compilation is done using external tools. The preferred build systems (Makefile, setup.py, and so on) should be configured as external tools.
C compiler should be downloaded and installed on your computer.
Get started with Cython in PyCharm
Follow this procedure to create a .pyx file in PyCharm, edit it, and build it into a .so file (.pyd on Windows) using setup.py.
Create a new project as explained in Create a Python project.
Ensure that the Cython package has been installed with the Python interpreter (). For more information about installing a package, refer to Install, uninstall, and upgrade packages.
Now create a .pyx file. Select from the main menu, then select . Type the filename, for example, example.pyx and save the changes. The file opens in the editor.
You can copy and paste the following code:
def function (a: int, b: int) -> str: return str(a + b) function(2, 4)Now create the setup.py file. Select from the main menu. PyCharm creates a template setup.py file and opens it in the editor. You can copy and paste the following setup options:
from setuptools import setup, Extension module = Extension ('example', sources=['example.pyx']) setup( name='cythonTest', version='1.0', author='jetbrains', ext_modules=[module] )To compile the example.pyx file, select command from the main menu. In the Enter setup.py task name type
buildand select the build_ext task. For more information, refer to Create and run setup.py.
In the Run Setup Task build_ext dialog, add the
--inplacecommand-line agrument
Once the build task successfully completes, the .so file (.pyd file on Windows) is created.

At this point, you can use the compiled file to import function:
See Cython documentation for the complete instructions.