Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | .. _extending-index: |
| 2 | |
| 3 | ################################################## |
| 4 | Extending and Embedding the Python Interpreter |
| 5 | ################################################## |
| 6 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 7 | This document describes how to write modules in C or C++ to extend the Python |
Georg Brandl | 7d07833 | 2013-10-06 18:36:34 +0200 | [diff] [blame] | 8 | interpreter with new modules. Those modules can not only define new functions |
| 9 | but also new object types and their methods. The document also describes how |
| 10 | to embed the Python interpreter in another application, for use as an extension |
| 11 | language. Finally, it shows how to compile and link extension modules so that |
| 12 | they can be loaded dynamically (at run time) into the interpreter, if the |
| 13 | underlying operating system supports this feature. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 14 | |
| 15 | This document assumes basic knowledge about Python. For an informal |
| 16 | introduction to the language, see :ref:`tutorial-index`. :ref:`reference-index` |
| 17 | gives a more formal definition of the language. :ref:`library-index` documents |
| 18 | the existing object types, functions and modules (both built-in and written in |
| 19 | Python) that give the language its wide application range. |
| 20 | |
| 21 | For a detailed description of the whole Python/C API, see the separate |
| 22 | :ref:`c-api-index`. |
| 23 | |
Nick Coghlan | b5c4fd0 | 2013-12-10 21:24:55 +1000 | [diff] [blame] | 24 | |
Nick Coghlan | f7614d5 | 2014-03-13 22:13:45 +1000 | [diff] [blame] | 25 | Recommended third party tools |
| 26 | ============================= |
Nick Coghlan | b5c4fd0 | 2013-12-10 21:24:55 +1000 | [diff] [blame] | 27 | |
Nick Coghlan | f7614d5 | 2014-03-13 22:13:45 +1000 | [diff] [blame] | 28 | This guide only covers the basic tools for creating extensions provided |
| 29 | as part of this version of CPython. Third party tools like Cython, |
| 30 | ``cffi``, SWIG and Numba offer both simpler and more sophisticated |
| 31 | approaches to creating C and C++ extensions for Python. |
| 32 | |
| 33 | .. seealso:: |
| 34 | |
| 35 | `Python Packaging User Guide: Binary Extensions <https://packaging.python.org/en/latest/extensions.html>`_ |
| 36 | The Python Packaging User Guide not only covers several available |
| 37 | tools that simplify the creation of binary extensions, but also |
| 38 | discusses the various reasons why creating an extension module may be |
| 39 | desirable in the first place. |
| 40 | |
| 41 | |
| 42 | Creating extensions without third party tools |
| 43 | ============================================= |
| 44 | |
| 45 | This section of the guide covers creating C and C++ extensions without |
| 46 | assistance from third party tools. It is intended primarily for creators |
| 47 | of those tools, rather than being a recommended way to create your own |
| 48 | C extensions. |
Nick Coghlan | b5c4fd0 | 2013-12-10 21:24:55 +1000 | [diff] [blame] | 49 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 50 | .. toctree:: |
| 51 | :maxdepth: 2 |
Benjamin Peterson | 5879d41 | 2009-03-30 14:51:56 +0000 | [diff] [blame] | 52 | :numbered: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 53 | |
| 54 | extending.rst |
| 55 | newtypes.rst |
| 56 | building.rst |
| 57 | windows.rst |
Nick Coghlan | f7614d5 | 2014-03-13 22:13:45 +1000 | [diff] [blame] | 58 | |
| 59 | Embedding the CPython runtime in a larger application |
| 60 | ===================================================== |
| 61 | |
| 62 | Sometimes, rather than creating an extension that runs inside the Python |
| 63 | interpreter as the main application, it is desirable to instead embed |
| 64 | the CPython runtime inside a larger application. This section covers |
| 65 | some of the details involved in doing that successfully. |
| 66 | |
| 67 | .. toctree:: |
| 68 | :maxdepth: 2 |
| 69 | :numbered: |
| 70 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 71 | embedding.rst |