Python インタプリタの拡張と埋め込み

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.

This document assumes basic knowledge about Python. For an informal introduction to the language, see Python チュートリアル. Python 言語リファレンス gives a more formal definition of the language. Python 標準ライブラリ documents the existing object types, functions and modules (both built-in and written in Python) that give the language its wide application range.

Python/C API 全体の詳しい説明は、別のドキュメントである、 Python/C API reference manual を参照してください。

Creating extensions without third party tools

ガイドのこの節ではサードパーティツールの補助無しに C および C++ 拡張を作成する方法を説明します。 これは自分自身の C 拡張を作成するおすすめの方法というよりも、主にそれらのツールを作成する人向けのものです。

参考

PEP 489 -- Multi-phase extension module initialization

大規模なアプリケーションへの Python ランタイムの埋め込み

Python インタープリタの中でメインアプリケーションとして実行される拡張を作るのではなく、 CPython をより大きなアプリケーションの中に埋め込む方が望ましいことがあります。 この節ではその上手い埋め込みに関わる詳細について説明します。