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

This document describes how to write modules in C or C++ to extend the
Python interpreter with new modules.  Those modules can do what Python
code does -- define functions, object types and methods -- but also
interact with native libraries or achieve better performance by
avoiding the overhead of an interpreter.  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 C and Python.  For an
informal introduction to Python, 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 を参照してください。

To support extensions, Python's C API (Application Programmers
Interface) defines a set of functions, macros and variables that
provide access to most aspects of the Python run-time system.  The
Python API is incorporated in a C source file by including the header
""Python.h"".

注釈:

  C 拡張のインターフェイスは CPython に固有のものであり、これによる拡
  張モジュールはほかの Python 実装では動作しません。多くの場合、C 拡張
  を書くことを避けてほかの Python 実装のために移植性を確保することは可
  能です。たとえば、あなたがしたいことが C ライブラリの関数やシステム
  コールを呼び出すことである場合、 "ctypes" あるいは cffi ライブラリの
  利用を検討すべきです。これらのモジュールは C コードとインターフェイ
  スし、C 拡張を書いてコンパイルするのに較べて Python 実装間のより高い
  移植性をもった Python コードを書かせてくれます。


おすすめのサードパーティツール
==============================

This document 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.

While this document is aimed at extension authors, it should also be
helpful to the authors of such tools. For example, the tutorial module
can serve as a simple test case for a build tool or sample expected
output of a code generator.


C API Tutorial
==============

This tutorial describes how to write a simple module in C or C++,
using the Python C API -- that is, using the basic tools provided as
part of this version of CPython.

1. Your first C API extension module


Guides for intermediate topics
==============================

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

* Using the C API: Assorted topics

* 拡張の型の定義: チュートリアル

* 拡張の型の定義: 雑多なトピック

* C および C++ 拡張のビルド

* Windows 上での C および C++ 拡張モジュールのビルド


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

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

* 他のアプリケーションへの Python の埋め込み
