| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
An alternative to using the C API directly is to rewrite a C extension using Cython which generates C code using the C API.
Cython allows you to wrap existing C code, but if you want to use Python objects in C or details which are not exposed at the Python level, you still need the Python C API to work with those.
The code that Cython generates is usually faster than the "obvious" C-API functions, so not using the C-API explicitly in Cython has many advantages, such as not relying on CPython version details, simplifying your code, and speeding it up.
Cython is not just a tool to "wrap existing C code". That's only one of its major use cases. Speeding up Python code, and writing C code without writing C code, are just as important.
Whether to use Cython or not depends on your use case. It's not always the obvious choice (otherwise, those other tools would not exist).
XXX write a better rationale why migrating to Cython!
Questions:
Small practical issue: Cython is not part of the Python 3.7 standard library yet.
See issue gh-89410: "[C API] Add explicit support for Cython to the C API".
See also :ref:`cffi <cffi>` and :ref:`Remove the C API <remove-c-api>`.
| Back | FazBrowse Home | New Git URL |