encyclopegia.org

Cython

Cython ( ) is a superset of the programming language Python, which allows developers to write Python code (with optional, C-inspired syntax extensions) that yields performance comparable to that of C.[src] Cython is a compiled language that is typically used to generate CPython extension modules.[src] Annotated Python-like code is compiled to C and then automatically wrapped in interface code, producing extension modules that can be loaded and used by regular Python code using the import statement, but with significantly less computational overhead at run time.[src] Cython also facilitates wrapping independent C or code into Python-importable modules.[src] Cython is written in Python and C and works on Windows, macOS, and Linux, producing C source files compatible with CPython 2.6, 2.7, and 3.3 and later versions.[src] The Cython source code that Cython compiles (to C) can use both Python 2 and Python 3 syntax, defaulting to Python 2 syntax in Cython 0.x and Python 3 syntax in Cython 3.x.[src] The default can be overridden (e.g.[src] in source code comment) to Python 3 (or 2) syntax.[src] Since Python 3 syntax has changed in recent versions, Cython may not be up to date with the latest additions.[src] Cython has "native support for most of the language" and "compiles almost all existing Python code".[src] Cython 3.0.0 was released on 17 July 2023.[src]

Cython ( ) is a superset of the programming language Python, which allows developers to write Python code (with optional, C-inspired syntax extensions) that yields performance comparable to that of C.[src] Cython is a compiled language that is typically used to generate CPython extension modules.[src] Annotated Python-like code is compiled to C and then automatically wrapped in interface code, producing extension modules that can be loaded and used by regular Python code using the import statement, but with significantly less computational overhead at run time.[src] Cython also facilitates wrapping independent C or code into Python-importable modules.[src] Cython is written in Python and C and works on Windows, macOS, and Linux, producing C source files compatible with CPython 2.6, 2.7, and 3.3 and later versions.[src] The Cython source code that Cython compiles (to C) can use both Python 2 and Python 3 syntax, defaulting to Python 2 syntax in Cython 0.x and Python 3 syntax in Cython 3.x.[src] The default can be overridden (e.g.[src] in source code comment) to Python 3 (or 2) syntax.[src] Since Python 3 syntax has changed in recent versions, Cython may not be up to date with the latest additions.[src] Cython has "native support for most of the language" and "compiles almost all existing Python code".[src] Cython 3.0.0 was released on 17 July 2023.[src] The argument will be converted to int or raise a TypeError.[src] def primes(int kmax): # These variables are declared with C types.[src] cdef int n, k, i # Another C type cdef int p[1000] # A Python type result = [] if kmax > 1000: kmax = 1000 k = 0 n = 2 while k hello.pyx - Python module, this code will be translated to C by Cython.[src] def say_hello(): print("Hello World!") launch.py - Python stub loader, loads the module that was made by Cython.[src] This code is always interpreted, like normal Python.[src] It is not compiled to C.[src] import hello hello.say_hello() setup.py - unnecessary if not redistributing the code, see below from setuptools import setup from Cython.Build import cythonize setup(name = "Hello world app", ext_modules = cythonize("*.pyx")) These commands build and launch the program: $ python setup.py build_ext --inplace $ python launch.py In [1]: %load_ext Cython In [2]: %%cython ...: def f(n): ...: a = 0 ...: for i in range(n): ...: a += i ...: return a ...: ...: cpdef g(int n): ...: cdef long a = 0 ...: cdef int i ...: for i in range(n): ...: a += i ...: return a ...: In [3]: %timeit f(1000000) 10 loops, best of 3: 26.5 ms per loop In [4]: %timeit g(1000000) 1000 loops, best of 3: 279 µs per loop which gives a 95 times improvement over the pure-python version.[src] More details on the subject in the official quickstart page.[src]

30 sentences · 30 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Cython." encyclopegia.org, 2026, https://encyclopegia.org/wiki/cython. Accessed 28 November 2026.

Chicago

"Cython." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/cython.

APA

encyclopegia.org. (2026). Cython. Retrieved November 28, 2026, from https://encyclopegia.org/wiki/cython

Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON

Claims

PredicateValueSource
release date2023-07-17Wikipedia
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1375360084 · 0.5 · snapshot enwiki-001375360084

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.