{
  "id": "enwiki-001375360084",
  "slug": "cython",
  "title": "Cython",
  "qid": "",
  "lead": "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. Cython is a compiled language that is typically used to generate CPython extension modules. 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. Cython also facilitates wrapping independent C or code into Python-importable modules. 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. 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. The default can be overridden (e.g. in source code comment) to Python 3 (or 2) syntax. Since Python 3 syntax has changed in recent versions, Cython may not be up to date with the latest additions. Cython has \"native support for most of the language\" and \"compiles almost all existing Python code\". Cython 3.0.0 was released on 17 July 2023.",
  "body": "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. Cython is a compiled language that is typically used to generate CPython extension modules. 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. Cython also facilitates wrapping independent C or code into Python-importable modules. 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. 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. The default can be overridden (e.g. in source code comment) to Python 3 (or 2) syntax. Since Python 3 syntax has changed in recent versions, Cython may not be up to date with the latest additions. Cython has \"native support for most of the language\" and \"compiles almost all existing Python code\". Cython 3.0.0 was released on 17 July 2023. The argument will be converted to int or raise a TypeError. def primes(int kmax): # These variables are declared with C types. 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. def say_hello(): print(\"Hello World!\") launch.py - Python stub loader, loads the module that was made by Cython. This code is always interpreted, like normal Python. It is not compiled to C. 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. More details on the subject in the official quickstart page.",
  "categories": [
    "106762838",
    "23118434",
    "23603337",
    "24165216",
    "24745117",
    "25257581",
    "31347309",
    "33243125",
    "60231904",
    "61575348",
    "9229844",
    "96940917",
    "96940993"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1375360084",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1789631867.0,
  "claims": [
    {
      "id": 30944613,
      "subject_qid": "",
      "subject_slug": "cython",
      "predicate": "release date",
      "object_text": "2023-07-17",
      "object_num": 20230717.0,
      "object_unit": null,
      "polarity": 1,
      "qualifier": "",
      "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1375360084",
      "source_name": "Wikipedia",
      "source_tier": 3,
      "retrieved_at": 1792498583.3886156,
      "confidence": 0.95,
      "article_slug": "cython",
      "span_start": 17,
      "span_end": 42
    }
  ],
  "contradictions": [],
  "confidence": 0.95,
  "csl": {
    "id": "enwiki-001375360084",
    "type": "webpage",
    "title": "Cython",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/cython",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          18
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          18
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001375360084",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1375360084",
    "note": "Immutable snapshot enwiki-001375360084"
  }
}