blob: 9eec8c273af30111ce56d1e7eb6de8bbdca6a3a2 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. _extending-index:
2
3##################################################
4 Extending and Embedding the Python Interpreter
5##################################################
6
Georg Brandl116aa622007-08-15 14:28:22 +00007This document describes how to write modules in C or C++ to extend the Python
Georg Brandl7d078332013-10-06 18:36:34 +02008interpreter with new modules. Those modules can not only define new functions
9but also new object types and their methods. The document also describes how
10to embed the Python interpreter in another application, for use as an extension
11language. Finally, it shows how to compile and link extension modules so that
12they can be loaded dynamically (at run time) into the interpreter, if the
13underlying operating system supports this feature.
Georg Brandl116aa622007-08-15 14:28:22 +000014
15This document assumes basic knowledge about Python. For an informal
16introduction to the language, see :ref:`tutorial-index`. :ref:`reference-index`
17gives a more formal definition of the language. :ref:`library-index` documents
18the existing object types, functions and modules (both built-in and written in
19Python) that give the language its wide application range.
20
21For a detailed description of the whole Python/C API, see the separate
22:ref:`c-api-index`.
23
Nick Coghlanb5c4fd02013-12-10 21:24:55 +100024
Nick Coghlanf7614d52014-03-13 22:13:45 +100025Recommended third party tools
26=============================
Nick Coghlanb5c4fd02013-12-10 21:24:55 +100027
Nick Coghlanf7614d52014-03-13 22:13:45 +100028This guide only covers the basic tools for creating extensions provided
29as part of this version of CPython. Third party tools like Cython,
30``cffi``, SWIG and Numba offer both simpler and more sophisticated
31approaches to creating C and C++ extensions for Python.
32
33.. seealso::
34
Georg Brandl5d941342016-02-26 19:37:12 +010035 `Python Packaging User Guide: Binary Extensions <https://packaging.python.org/en/latest/extensions/>`_
Nick Coghlanf7614d52014-03-13 22:13:45 +100036 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
42Creating extensions without third party tools
43=============================================
44
45This section of the guide covers creating C and C++ extensions without
46assistance from third party tools. It is intended primarily for creators
47of those tools, rather than being a recommended way to create your own
48C extensions.
Nick Coghlanb5c4fd02013-12-10 21:24:55 +100049
Georg Brandl116aa622007-08-15 14:28:22 +000050.. toctree::
51 :maxdepth: 2
Benjamin Peterson5879d412009-03-30 14:51:56 +000052 :numbered:
Georg Brandl116aa622007-08-15 14:28:22 +000053
54 extending.rst
55 newtypes.rst
56 building.rst
57 windows.rst
Nick Coghlanf7614d52014-03-13 22:13:45 +100058
59Embedding the CPython runtime in a larger application
60=====================================================
61
62Sometimes, rather than creating an extension that runs inside the Python
63interpreter as the main application, it is desirable to instead embed
64the CPython runtime inside a larger application. This section covers
65some of the details involved in doing that successfully.
66
67.. toctree::
68 :maxdepth: 2
69 :numbered:
70
Georg Brandl116aa622007-08-15 14:28:22 +000071 embedding.rst