summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/extending%2Findex.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/python~3.12/extending%2Findex.html
new repository
Diffstat (limited to 'devdocs/python~3.12/extending%2Findex.html')
-rw-r--r--devdocs/python~3.12/extending%2Findex.html14
1 files changed, 14 insertions, 0 deletions
diff --git a/devdocs/python~3.12/extending%2Findex.html b/devdocs/python~3.12/extending%2Findex.html
new file mode 100644
index 00000000..f748a326
--- /dev/null
+++ b/devdocs/python~3.12/extending%2Findex.html
@@ -0,0 +1,14 @@
+ <span id="extending-index"></span><h1>Extending and Embedding the Python Interpreter</h1> <p>This document describes how to write modules in C or C++ to extend the Python interpreter with new modules. Those modules can not only define new functions but also new object types and their methods. The document also describes how to embed the Python interpreter in another application, for use as an extension language. Finally, it shows how to compile and link extension modules so that they can be loaded dynamically (at run time) into the interpreter, if the underlying operating system supports this feature.</p> <p>This document assumes basic knowledge about Python. For an informal introduction to the language, see <a class="reference internal" href="../tutorial/index#tutorial-index"><span class="std std-ref">The Python Tutorial</span></a>. <a class="reference internal" href="../reference/index#reference-index"><span class="std std-ref">The Python Language Reference</span></a> gives a more formal definition of the language. <a class="reference internal" href="../library/index#library-index"><span class="std std-ref">The Python Standard Library</span></a> documents the existing object types, functions and modules (both built-in and written in Python) that give the language its wide application range.</p> <p>For a detailed description of the whole Python/C API, see the separate <a class="reference internal" href="../c-api/index#c-api-index"><span class="std std-ref">Python/C API Reference Manual</span></a>.</p> <section id="recommended-third-party-tools"> <h2>Recommended third party tools</h2> <p>This guide only covers the basic tools for creating extensions provided as part of this version of CPython. Third party tools like <a class="reference external" href="https://cython.org/">Cython</a>, <a class="reference external" href="https://cffi.readthedocs.io">cffi</a>, <a class="reference external" href="https://www.swig.org">SWIG</a> and <a class="reference external" href="https://numba.pydata.org/">Numba</a> offer both simpler and more sophisticated approaches to creating C and C++ extensions for Python.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt><a class="reference external" href="https://packaging.python.org/guides/packaging-binary-extensions/">Python Packaging User Guide: Binary Extensions</a></dt>
+<dd>
+<p>The Python Packaging User Guide not only covers several available tools that simplify the creation of binary extensions, but also discusses the various reasons why creating an extension module may be desirable in the first place.</p> </dd> </dl> </div> </section> <section id="creating-extensions-without-third-party-tools"> <h2>Creating extensions without third party tools</h2> <p>This section of the guide covers creating C and C++ extensions without assistance from third party tools. It is intended primarily for creators of those tools, rather than being a recommended way to create your own C extensions.</p> <ul> <li class="toctree-l1">
+<a class="reference internal" href="extending">1. Extending Python with C or C++</a><ul> <li class="toctree-l2"><a class="reference internal" href="extending#a-simple-example">1.1. A Simple Example</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#intermezzo-errors-and-exceptions">1.2. Intermezzo: Errors and Exceptions</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#back-to-the-example">1.3. Back to the Example</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#the-module-s-method-table-and-initialization-function">1.4. The Module’s Method Table and Initialization Function</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#compilation-and-linkage">1.5. Compilation and Linkage</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#calling-python-functions-from-c">1.6. Calling Python Functions from C</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#extracting-parameters-in-extension-functions">1.7. Extracting Parameters in Extension Functions</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#keyword-parameters-for-extension-functions">1.8. Keyword Parameters for Extension Functions</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#building-arbitrary-values">1.9. Building Arbitrary Values</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#reference-counts">1.10. Reference Counts</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#writing-extensions-in-c">1.11. Writing Extensions in C++</a></li> <li class="toctree-l2"><a class="reference internal" href="extending#providing-a-c-api-for-an-extension-module">1.12. Providing a C API for an Extension Module</a></li> </ul> </li> <li class="toctree-l1">
+<a class="reference internal" href="newtypes_tutorial">2. Defining Extension Types: Tutorial</a><ul> <li class="toctree-l2"><a class="reference internal" href="newtypes_tutorial#the-basics">2.1. The Basics</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes_tutorial#adding-data-and-methods-to-the-basic-example">2.2. Adding data and methods to the Basic example</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes_tutorial#providing-finer-control-over-data-attributes">2.3. Providing finer control over data attributes</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes_tutorial#supporting-cyclic-garbage-collection">2.4. Supporting cyclic garbage collection</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes_tutorial#subclassing-other-types">2.5. Subclassing other types</a></li> </ul> </li> <li class="toctree-l1">
+<a class="reference internal" href="newtypes">3. Defining Extension Types: Assorted Topics</a><ul> <li class="toctree-l2"><a class="reference internal" href="newtypes#finalization-and-de-allocation">3.1. Finalization and De-allocation</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes#object-presentation">3.2. Object Presentation</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes#attribute-management">3.3. Attribute Management</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes#object-comparison">3.4. Object Comparison</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes#abstract-protocol-support">3.5. Abstract Protocol Support</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes#weak-reference-support">3.6. Weak Reference Support</a></li> <li class="toctree-l2"><a class="reference internal" href="newtypes#more-suggestions">3.7. More Suggestions</a></li> </ul> </li> <li class="toctree-l1">
+<a class="reference internal" href="building">4. Building C and C++ Extensions</a><ul> <li class="toctree-l2"><a class="reference internal" href="building#building-c-and-c-extensions-with-setuptools">4.1. Building C and C++ Extensions with setuptools</a></li> </ul> </li> <li class="toctree-l1">
+<a class="reference internal" href="windows">5. Building C and C++ Extensions on Windows</a><ul> <li class="toctree-l2"><a class="reference internal" href="windows#a-cookbook-approach">5.1. A Cookbook Approach</a></li> <li class="toctree-l2"><a class="reference internal" href="windows#differences-between-unix-and-windows">5.2. Differences Between Unix and Windows</a></li> <li class="toctree-l2"><a class="reference internal" href="windows#using-dlls-in-practice">5.3. Using DLLs in Practice</a></li> </ul> </li> </ul> </section> <section id="embedding-the-cpython-runtime-in-a-larger-application"> <h2>Embedding the CPython runtime in a larger application</h2> <p>Sometimes, rather than creating an extension that runs inside the Python interpreter as the main application, it is desirable to instead embed the CPython runtime inside a larger application. This section covers some of the details involved in doing that successfully.</p> <ul> <li class="toctree-l1">
+<a class="reference internal" href="embedding">1. Embedding Python in Another Application</a><ul> <li class="toctree-l2"><a class="reference internal" href="embedding#very-high-level-embedding">1.1. Very High Level Embedding</a></li> <li class="toctree-l2"><a class="reference internal" href="embedding#beyond-very-high-level-embedding-an-overview">1.2. Beyond Very High Level Embedding: An overview</a></li> <li class="toctree-l2"><a class="reference internal" href="embedding#pure-embedding">1.3. Pure Embedding</a></li> <li class="toctree-l2"><a class="reference internal" href="embedding#extending-embedded-python">1.4. Extending Embedded Python</a></li> <li class="toctree-l2"><a class="reference internal" href="embedding#embedding-python-in-c">1.5. Embedding Python in C++</a></li> <li class="toctree-l2"><a class="reference internal" href="embedding#compiling-and-linking-under-unix-like-systems">1.6. Compiling and Linking under Unix-like systems</a></li> </ul> </li> </ul> </section> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/extending/index.html" class="_attribution-link">https://docs.python.org/3.12/extending/index.html</a>
+ </p>
+</div>