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.

このドキュメントは、C と Python の基礎知識を前提としています。 Python の入門には Python チュートリアル を参照してください。 Python 言語リファレンス には、より厳密な言語の定義があります。 Python 組み込み機能リファレンス は組み込み関数とオブジェクト型を説明し、Python 標準ライブラリ は Python の幅広い用途を支えるモジュール (組み込みモジュールと Python で書かれたモジュールの両方) を説明します。

Python/C API 全体の詳しい説明は、別のドキュメントである、 Python/C API リファレンスマニュアル を参照してください。

Creating extensions without third party tools

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

参考

PEP 489 -- Multi-phase extension module initialization

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

Python インタープリタをメインアプリケーションとして、その中で実行する拡張を作るよりも、大きなアプリケーションの中に CPython ランタイムを組み込む方が望ましい場合があります。 この節では、そのために必要な詳細の一部を説明します。