https://github.com/cython/cython
The most widely used Python to C compiler
https://github.com/cython/cython
big-data c cpp cpython cpython-extensions cython performance python
Last synced: 26 days ago
JSON representation
The most widely used Python to C compiler
- Host: GitHub
- URL: https://github.com/cython/cython
- Owner: cython
- License: apache-2.0
- Created: 2010-11-21T07:44:20.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2025-05-12T09:03:10.000Z (5 months ago)
- Last Synced: 2025-05-12T18:13:02.883Z (5 months ago)
- Topics: big-data, c, cpp, cpython, cpython-extensions, cython, performance, python
- Language: Python
- Homepage: https://cython.org
- Size: 72.1 MB
- Stars: 9,987
- Watchers: 238
- Forks: 1,525
- Open Issues: 1,437
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: COPYING.txt
- Code of conduct: .github/code-of-conduct.md
Awesome Lists containing this project
- awesome-python-applications - Repo - performance Python and C interoperability. `(linux, windows, mac)` (<a id="tag-dev" href="#tag-dev">Dev</a> / <a id="tag-dev-other" href="#tag-dev-other">Other Dev projects</a>)
- awesome-systematic-trading - cython - commit/cython/cython/master)  - Cython is a Python compiler that makes writing C extensions for Python as easy as Python itself. Cython is based on Pyrex, but supports more cutting edge functionality and optimizations. (Basic Components / Python Performance Booster)
- awesome-python-applications - Repo - performance Python and C interoperability. `(linux, windows, mac)` (<a id="tag-dev" href="#tag-dev">Dev</a> / <a id="tag-dev-other" href="#tag-dev-other">Other Dev projects</a>)
- awesome-mojo - Cython
README
Welcome to Cython!
==================Cython is an optimising Python compiler that makes writing C extensions for
Python as easy as Python itself.Cython translates Python code to C/C++ code, but additionally supports calling
C functions and declaring C types on variables and class attributes.
This allows broad to fine-grained manual tuning that lets the compiler
generate very efficient C code from Cython code.This makes Cython the ideal language for wrapping external C libraries, and
for fast C modules that speed up the execution of Python code.* Official website: https://cython.org/
* Documentation: https://docs.cython.org/
* Github repository: https://github.com/cython/cython
* Wiki: https://github.com/cython/cython/wikiCython has `more than 70 million downloads `_
per month on PyPI. You can **support the Cython project** via
`Github Sponsors `_ or
`Tidelift `_.Installation:
-------------If you already have a C compiler, just run following command::
pip install Cython
otherwise, see `the installation page `_.
License:
--------The original Pyrex program, which Cython is based on, was licensed "free of restrictions" (see below).
Cython itself is licensed under the permissive **Apache License**.See `LICENSE.txt `_.
Contributing:
-------------Want to contribute to the Cython project?
Here is some `help to get you started `_.Differences to other Python compilers
-------------------------------------Started as a project in the early 2000s, Cython has outlived
`most other attempts `_
at producing static compilers for the Python language.Similar projects that have a relevance today include:
* `PyPy `_, a Python implementation with a JIT compiler.
* Pros: JIT compilation with runtime optimisations, fully language compliant,
good integration with external C/C++ code
* Cons: non-CPython runtime, relatively large resource usage of the runtime,
limited compatibility with CPython extensions, non-obvious performance results* `Numba `_, a Python extension that features a
JIT compiler for a subset of the language, based on the LLVM compiler
infrastructure (probably best known for its ``clang`` C compiler).
It mostly targets numerical code that uses NumPy.* Pros: JIT compilation with runtime optimisations
* Cons: limited language support, relatively large runtime dependency (LLVM),
non-obvious performance results* `Pythran `_, a static Python-to-C++
extension compiler for a subset of the language, mostly targeted
at numerical computation. Pythran can be (and is probably best) used
as an additional
`backend for NumPy code `_
in Cython.* `mypyc `_, a static Python-to-C extension
compiler, based on the `mypy `_ static Python
analyser. Like Cython's
`pure Python mode `_,
mypyc can make use of PEP-484 type annotations to optimise code for static types.* Pros: good support for language and PEP-484 typing, good type inference,
reasonable performance gains
* Cons: no support for low-level optimisations and typing,
opinionated Python type interpretation, reduced Python compatibility
and introspection after compilation* `Nuitka `_, a static Python-to-C extension compiler.
* Pros: highly language compliant, reasonable performance gains,
support for static application linking (similar to
`cython_freeze `_
but with the ability to bundle library dependencies into a self-contained
executable)
* Cons: no support for low-level optimisations and typingIn comparison to the above, Cython provides
* fast, efficient and highly compliant support for almost all
Python language features, including dynamic features and introspection
* full runtime compatibility with all still-in-use and future versions
of CPython
* "generate once, compile everywhere" C code generation that allows for
reproducible performance results and testing
* C compile time adaptation to the target platform and Python version
* support for other C-API implementations, including PyPy and Pyston
* seamless integration with C/C++ code
* broad support for manual optimisation and tuning down to the C level
* a large user base with thousands of libraries, packages and tools
* more than two decades of bug fixing and static code optimisationsThe following is from Pyrex:
------------------------------------------------------
Cython was originally based on `Pyrex `_
by Greg Ewing, with the following written in the Pyrex readme document:This is a development version of Pyrex, a language
for writing Python extension modules.For more info, take a look at:
* Doc/About.html for a description of the language
* INSTALL.txt for installation instructions
* USAGE.txt for usage instructions
* Demos for usage examplesComments, suggestions, bug reports, etc. are most
welcome!Copyright stuff: Pyrex is free of restrictions. You
may use, redistribute, modify and distribute modified
versions.The latest version of Pyrex can be found `here `_.
| Greg Ewing, Computer Science Dept
| University of Canterbury
| Christchurch, New ZealandA citizen of NewZealandCorp, a wholly-owned subsidiary of USA Inc.