• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _extending-index:
2
3##################################################
4  Extending and Embedding the Python Interpreter
5##################################################
6
7This document describes how to write modules in C or C++ to extend the Python
8interpreter 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.
14
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
24
25Recommended third party tools
26=============================
27
28This guide only covers the basic tools for creating extensions provided
29as part of this version of CPython. Third party tools like
30`Cython <http://cython.org/>`_, `cffi <https://cffi.readthedocs.io>`_,
31`SWIG <http://www.swig.org>`_ and `Numba <https://numba.pydata.org/>`_
32offer both simpler and more sophisticated approaches to creating C and C++
33extensions for Python.
34
35.. seealso::
36
37   `Python Packaging User Guide: Binary Extensions <https://packaging.python.org/guides/packaging-binary-extensions/>`_
38      The Python Packaging User Guide not only covers several available
39      tools that simplify the creation of binary extensions, but also
40      discusses the various reasons why creating an extension module may be
41      desirable in the first place.
42
43
44Creating extensions without third party tools
45=============================================
46
47This section of the guide covers creating C and C++ extensions without
48assistance from third party tools. It is intended primarily for creators
49of those tools, rather than being a recommended way to create your own
50C extensions.
51
52.. toctree::
53   :maxdepth: 2
54   :numbered:
55
56   extending.rst
57   newtypes_tutorial.rst
58   newtypes.rst
59   building.rst
60   windows.rst
61
62Embedding the CPython runtime in a larger application
63=====================================================
64
65Sometimes, rather than creating an extension that runs inside the Python
66interpreter as the main application, it is desirable to instead embed
67the CPython runtime inside a larger application. This section covers
68some of the details involved in doing that successfully.
69
70.. toctree::
71   :maxdepth: 2
72   :numbered:
73
74   embedding.rst
75