{"id":431,"library":"cython","title":"Cython: C-Extensions for Python","description":"Cython is an optimizing static compiler for both the Python programming language and the extended Cython programming language, making writing C extensions for Python as easy as Python itself. Current version: 3.2.4. Release cadence: Regular updates with active development and maintenance.","status":"active","version":"3.2.4","language":"python","source_language":"en","source_url":"https://github.com/cython/cython","tags":["Cython","Python","C extensions","compiler","performance"],"install":[{"cmd":"pip install cython","lang":"bash","label":"Install Cython"}],"dependencies":[{"reason":"Required for building Cython extensions","package":"setuptools","optional":false}],"imports":[{"note":"Necessary for using Cython-specific features","symbol":"cython","correct":"import cython"}],"quickstart":{"code":"import cython\n\n@cython.cfunc\n@cython.exceptval(-1)\ndef add(int x, int y):\n    return x + y\n\nprint(add(2, 3))","lang":"python","description":"A simple example demonstrating the use of Cython's cfunc decorator to define a C function in Python."},"warnings":[{"fix":"Upgrade to Python 3.8 or later.","message":"Support for Python 2.7 - 3.7 was removed in Cython 3.3.0a0, along with large chunks of legacy code.","severity":"breaking","affected_versions":"3.3.0a0"},{"fix":"Upgrade to the latest Cython 3 release.","message":"Using the pure Python syntax for static type declarations requires a recent Cython 3 release due to significant improvements over the 0.29.x releases.","severity":"gotcha","affected_versions":"0.29.x"},{"fix":"Compile the script with Cython or rewrite the code using standard Python type hints (e.g., `x: int`).","message":"The script uses Cython-specific C-style parameter declarations (e.g., `int x`), which are invalid in standard Python and will result in a `SyntaxError`. This syntax is only recognized by the Cython compiler.","severity":"breaking","affected_versions":"N/A (occurs when executing Cython syntax in a standard Python interpreter)"}],"env_vars":null,"last_verified":"2026-05-12T13:45:25.840Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure Cython is installed in your active Python environment by running: `pip install Cython`","cause":"This error occurs when the Cython package itself is not installed in the Python environment you are using, or it's installed in a different environment or Python version.","error":"ModuleNotFoundError: No module named 'Cython'"},{"fix":"Install the 'Desktop development with C++' workload from Visual Studio Installer, or specifically the 'Microsoft C++ Build Tools' (available at visualstudio.microsoft.com/visual-cpp-build-tools/). Ensure your environment variables are correctly set for the compiler.","cause":"On Windows, compiling Cython extensions (which generate C/C++ code) requires a compatible C++ compiler, typically provided by the Microsoft C++ Build Tools or a Visual Studio installation.","error":"error: Microsoft Visual C++ 14.0 or greater is required."},{"fix":"For pickling custom extension types, you need to explicitly implement `__reduce_cython__` and `__setstate_cython__` methods in your Cython class, or use the `@cython.auto_pickle(True)` decorator if applicable (though explicit implementation is generally safer for complex types).","cause":"This error typically arises when trying to pickle or copy a Cython extension type that does not have proper serialization methods (`__reduce_cython__` and `__setstate_cython__`) defined, often after upgrading Cython or Python, or when using libraries like PyInstaller.","error":"AttributeError: type object 'your_module.YourCythonClass' has no attribute '__reduce_cython__'"},{"fix":"Debug the Cython code to identify memory-related issues. Common steps include enabling Cython directives like `boundscheck=True` and `wraparound=True` during development, carefully managing C pointers and `malloc`/`free`, and using tools like `gdb` for C-level debugging.","cause":"A segmentation fault in Cython code usually indicates a low-level memory access error, such as reading or writing beyond allocated memory bounds, using uninitialized C pointers, or incorrect memory management when interacting with C libraries.","error":"Segmentation fault"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"30.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"32M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.4,"disk_size":"34.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.4,"disk_size":"36M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"26.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"27M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.3,"disk_size":"25.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"27M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"30.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"32M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}