17db96d56Sopenharmony_ci.. _extending-index:
27db96d56Sopenharmony_ci
37db96d56Sopenharmony_ci##################################################
47db96d56Sopenharmony_ci  Extending and Embedding the Python Interpreter
57db96d56Sopenharmony_ci##################################################
67db96d56Sopenharmony_ci
77db96d56Sopenharmony_ciThis document describes how to write modules in C or C++ to extend the Python
87db96d56Sopenharmony_ciinterpreter with new modules.  Those modules can not only define new functions
97db96d56Sopenharmony_cibut also new object types and their methods.  The document also describes how
107db96d56Sopenharmony_cito embed the Python interpreter in another application, for use as an extension
117db96d56Sopenharmony_cilanguage.  Finally, it shows how to compile and link extension modules so that
127db96d56Sopenharmony_cithey can be loaded dynamically (at run time) into the interpreter, if the
137db96d56Sopenharmony_ciunderlying operating system supports this feature.
147db96d56Sopenharmony_ci
157db96d56Sopenharmony_ciThis document assumes basic knowledge about Python.  For an informal
167db96d56Sopenharmony_ciintroduction to the language, see :ref:`tutorial-index`.  :ref:`reference-index`
177db96d56Sopenharmony_cigives a more formal definition of the language.  :ref:`library-index` documents
187db96d56Sopenharmony_cithe existing object types, functions and modules (both built-in and written in
197db96d56Sopenharmony_ciPython) that give the language its wide application range.
207db96d56Sopenharmony_ci
217db96d56Sopenharmony_ciFor a detailed description of the whole Python/C API, see the separate
227db96d56Sopenharmony_ci:ref:`c-api-index`.
237db96d56Sopenharmony_ci
247db96d56Sopenharmony_ci
257db96d56Sopenharmony_ciRecommended third party tools
267db96d56Sopenharmony_ci=============================
277db96d56Sopenharmony_ci
287db96d56Sopenharmony_ciThis guide only covers the basic tools for creating extensions provided
297db96d56Sopenharmony_cias part of this version of CPython. Third party tools like
307db96d56Sopenharmony_ci`Cython <https://cython.org/>`_, `cffi <https://cffi.readthedocs.io>`_,
317db96d56Sopenharmony_ci`SWIG <https://www.swig.org>`_ and `Numba <https://numba.pydata.org/>`_
327db96d56Sopenharmony_cioffer both simpler and more sophisticated approaches to creating C and C++
337db96d56Sopenharmony_ciextensions for Python.
347db96d56Sopenharmony_ci
357db96d56Sopenharmony_ci.. seealso::
367db96d56Sopenharmony_ci
377db96d56Sopenharmony_ci   `Python Packaging User Guide: Binary Extensions <https://packaging.python.org/guides/packaging-binary-extensions/>`_
387db96d56Sopenharmony_ci      The Python Packaging User Guide not only covers several available
397db96d56Sopenharmony_ci      tools that simplify the creation of binary extensions, but also
407db96d56Sopenharmony_ci      discusses the various reasons why creating an extension module may be
417db96d56Sopenharmony_ci      desirable in the first place.
427db96d56Sopenharmony_ci
437db96d56Sopenharmony_ci
447db96d56Sopenharmony_ciCreating extensions without third party tools
457db96d56Sopenharmony_ci=============================================
467db96d56Sopenharmony_ci
477db96d56Sopenharmony_ciThis section of the guide covers creating C and C++ extensions without
487db96d56Sopenharmony_ciassistance from third party tools. It is intended primarily for creators
497db96d56Sopenharmony_ciof those tools, rather than being a recommended way to create your own
507db96d56Sopenharmony_ciC extensions.
517db96d56Sopenharmony_ci
527db96d56Sopenharmony_ci.. toctree::
537db96d56Sopenharmony_ci   :maxdepth: 2
547db96d56Sopenharmony_ci   :numbered:
557db96d56Sopenharmony_ci
567db96d56Sopenharmony_ci   extending.rst
577db96d56Sopenharmony_ci   newtypes_tutorial.rst
587db96d56Sopenharmony_ci   newtypes.rst
597db96d56Sopenharmony_ci   building.rst
607db96d56Sopenharmony_ci   windows.rst
617db96d56Sopenharmony_ci
627db96d56Sopenharmony_ciEmbedding the CPython runtime in a larger application
637db96d56Sopenharmony_ci=====================================================
647db96d56Sopenharmony_ci
657db96d56Sopenharmony_ciSometimes, rather than creating an extension that runs inside the Python
667db96d56Sopenharmony_ciinterpreter as the main application, it is desirable to instead embed
677db96d56Sopenharmony_cithe CPython runtime inside a larger application. This section covers
687db96d56Sopenharmony_cisome of the details involved in doing that successfully.
697db96d56Sopenharmony_ci
707db96d56Sopenharmony_ci.. toctree::
717db96d56Sopenharmony_ci   :maxdepth: 2
727db96d56Sopenharmony_ci   :numbered:
737db96d56Sopenharmony_ci
747db96d56Sopenharmony_ci   embedding.rst
75