Python
docs.python.org › 3 › c-api › index.html
Python/C API reference manual — Python 3.14.7 documentation
This manual documents the API used by C and C++ programmers who want to write extension modules or embed Python. It is a companion to Extending and Embedding the Python Interpreter, which describes...
20:41
a "hello world" python C extension (intermediate - advanced) anthony ...
03:03
Python-C Interaction: Exploring the C API (ep 01) - Run Python ...
36:07
NumPy C-API (Python C extensions) - YouTube
22:18
How to use C from Python? - #9 - YouTube
30:04
Sophia Davis - Peeking into Python’s C API - YouTube
Cornell Virtual Workshop
cvw.cac.cornell.edu › python-performance › intro › cpython-api
Cornell Virtual Workshop > Python for High Performance > Overview > CPython and the Python/C API
The Python/C API allows for compiled pieces of code to be called from Python programs or executed within the CPython interpreter.
Starred by 5 users
Forked by 2 users
Languages: C++ 56.8% | CMake 21.2% | C 19.1% | Python 2.9%
Reddit
reddit.com › r/python › askpython: best tutorials/examples of the python c api?
r/Python on Reddit: AskPython: Best Tutorials/Examples of the Python C API?
December 14, 2009 -
--excluding the official documentation. I'm looking for a good comprehensive tutorial that uses both examples and explains what's happening.
edit I have no idea why this is being downvoted. If you aren't interested, don't upvote it. This isn't spam, it's in the right category, and I'm just looking for advice. Just plain poor reddiquette.
Top answer 1 of 3
3
I don't know, I went through the python docs in detail once and could write some basic extensions in C but then I decided to try out cython and never looked back :) Have you tried cython ?
2 of 3
3
Ned Batchelder's "A Whirlwind Tour through Python C Extensions" is the absolute best I have found online: http://nedbatchelder.com/text/whirlext.html Examples are clear and straightforward; I followed along at PyCon 2009 and had a C extension module running in minutes. This is probably exactly what you want. Another good reference is David Beazley's coverage of it in Python Essential Reference, but that's not available freely online.
SciPy Lecture Notes
scipy-lectures.org › advanced › interfacing_with_c › interfacing_with_c.html
2.8. Interfacing with C — Scipy lecture notes
Since reference counting bugs are easy to create and hard to track down, anyone really needing to use the Python C-API should read the section about objects, types and reference counts from the official python documentation. Additionally, there is a tool by the name of cpychecker which can help discover common errors with reference counting. The following C-extension module, make the cos function from the standard math library available to Python: /* Example of wrapping cos function from math.h with the Python-C-API.
Python
docs.python.org › 3 › c-api
Python/C API reference manual — Python 3.14.6 documentation
This manual documents the API used by C and C++ programmers who want to write extension modules or embed Python. It is a companion to Extending and Embedding the Python Interpreter, which describes...
Python Tips
book.pythontips.com › en › latest › python_c_extension.html
22. Python C extensions — Python Tips 0.1 documentation
In this example the C file is self explanatory - it contains two functions, one to add two integers and another to add two floats. In the python file, first the ctypes module is imported. Then the CDLL function of the ctypes module is used to load the shared lib file we created.
Cornell Virtual Workshop
cvw.cac.cornell.edu › python › api
Cornell Virtual Workshop: CPython and the Python/C API
The CPython interpreter (aka, "python") works by compiling Python source code to intermediate bytecodes, and then operating on those. CPython, which is written in C, is also accompanied by an Application Programming Interface (API) that enables communication between Python and C (and thus basically ...
Python
docs.python.org › 3.8 › c-api › intro.html
Introduction — Python 3.8.20 documentation
C++ users should note that although the API is defined entirely using C, the header files properly declare the entry points to be extern "C". As a result, there is no need to do anything special to use the API from C++. Several useful macros are defined in the Python header files. Many are defined closer to where they are useful (e.g. Py_RETURN_NONE). Others of a more general utility are defined here. This is not necessarily a complete listing. ... Use this when you have a code path that you do not expect to be reached. For example, in the default: clause in a switch statement for which all possible values are covered in case statements.