Python インタプリタの拡張と埋め込み¶
このドキュメントでは、Pythonインタプリンタを拡張する新しいモジュールをで C またはC++ で書く方法を解説しています。このようなモジュールでは新しい関数を定義するだけではなく、新しい型や、そのメソッドを定義することができます。ドキュメントでは他のアプリケーションでPythonを拡張言語として使用するために、Pythonインタプリタをアプリケーションに埋め込む方法についても解説します。最後に、下層のオペレーティングシステムが動的(実行時)ロードをサポートしていれば、拡張モジュールが動的にライブラリにロードされるように、モジュールをコンパイルしリンクする方法について解説します。
This document assumes basic knowledge about C and Python. For an informal introduction to Python, see Python チュートリアル. Python 言語リファレンス gives a more formal definition of the language. Python built-ins reference documents the built-in functions and object types, and The Python standard library documents the modules (both built-in and written in Python) that give the language its wide application range.
Python/C API 全体の詳しい説明は、別のドキュメントである、 Python/C API リファレンスマニュアル を参照してください。
おすすめのサードパーティツール¶
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.
サードパーティツールなしで拡張を作る¶
ガイドのこの節ではサードパーティツールの補助無しに C および C++ 拡張を作成する方法を説明します。 これは自分自身の C 拡張を作成するおすすめの方法というよりも、主にそれらのツールを作成する人向けのものです。
参考
PEP 489 -- Multi-phase extension module initialization
大規模なアプリケーションへの Python ランタイムの埋め込み¶
Python インタープリタの中でメインアプリケーションとして実行される拡張を作るのではなく、 CPython をより大きなアプリケーションの中に埋め込む方が望ましいことがあります。 この節ではその上手い埋め込みに関わる詳細について説明します。