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 を参照してください。
おすすめのサードパーティツール¶
This guide only covers the basic tools for creating extensions provided as part of this version of CPython. Some third party tools offer both simpler and more sophisticated approaches to creating C and C++ extensions for Python.
Creating extensions without third party tools¶
ガイドのこの節ではサードパーティツールの補助無しに C および C++ 拡張を作成する方法を説明します。 これは自分自身の C 拡張を作成するおすすめの方法というよりも、主にそれらのツールを作成する人向けのものです。
参考
PEP 489 -- Multi-phase extension module initialization
- 1. Extending Python with C or C++
- 1.1. A Simple Example
- 1.2. Intermezzo: Errors and Exceptions
- 1.3. Back to the Example
- 1.4. The Module's Method Table and Initialization Function
- 1.5. Compilation and Linkage
- 1.6. C から Python 関数を呼び出す
- 1.7. 拡張モジュール関数でのパラメタ展開
- 1.8. 拡張モジュール関数のキーワードパラメタ
- 1.9. 任意の値を構築する
- 1.10. 参照カウント法
- 1.11. C++での拡張モジュール作成
- 1.12. 拡張モジュールに C API を提供する
- 2. 拡張の型の定義: チュートリアル
- 3. 拡張の型の定義: 雑多なトピック
- 4. C および C++ 拡張のビルド
- 5. Windows 上での C および C++ 拡張モジュールのビルド
大規模なアプリケーションへの Python ランタイムの埋め込み¶
Python インタープリタの中でメインアプリケーションとして実行される拡張を作るのではなく、 CPython をより大きなアプリケーションの中に埋め込む方が望ましいことがあります。 この節ではその上手い埋め込みに関わる詳細について説明します。