The Python C API, reference ownership rules, creating extension modules, defining new types, the buffer protocol, capsules, stable ABI, limited API, embedding Python, and cross-language calls.
| Chapter | Title |
|---|---|
| 61 | The Python C API |
| 62 | Reference Ownership Rules |
| 63 | Creating Extension Modules |
| 64 | Defining New Types |
| 65 | Buffer Protocol |
| 66 | Capsules |
| 67 | Stable ABI |
| 68 | Limited API |
| 69 | Embedding Python |
| 70 | Calling Python From C |
| 71 | Calling C From Python |
61. The Python C APIPublic C API overview, Include/ header organization, and the stable vs. internal API distinction.
62. Reference Ownership RulesBorrowed vs. owned references, Py_XDECREF patterns, and common reference counting mistakes in extensions.
63. Creating Extension ModulesPyModuleDef structure, PyModule_Create, multi-phase initialization (PEP 451), and module state.
64. Defining New TypesPyTypeObject slot-by-slot walkthrough: tp_new, tp_init, tp_dealloc, tp_methods, tp_getset, and inheritance.
65. Buffer ProtocolPy_buffer, PyBUF_* flags, PyObject_GetBuffer, and implementing the buffer protocol in a custom type.
66. CapsulesPyCapsule_New, PyCapsule_GetPointer, and the pattern for passing opaque C pointers between extension modules.
67. Stable ABIThe stable ABI symbol set, abi3 wheel tagging, and the constraints imposed by maintaining ABI compatibility.
68. Limited APIPy_LIMITED_API version macros, symbols excluded from the limited API, and building abi3-compatible extensions.
69. Embedding PythonPy_Initialize, PyConfig, embedding CPython in a host process, and managing interpreter lifetime.
70. Calling Python From CPyObject_Call, PyObject_CallNoArgs, argument tuple construction, and error checking after calling into Python.
71. Calling C From Pythonctypes, cffi, and CFFI-based extension dispatch as the primary paths for calling C libraries from Python.