扩展和嵌入Python解释器

本文档描述了如何在C或C中编写模块以使用新模块扩展Python解释器。 这些模块不仅可以定义新的功能,还可以定义新的对象类型及其方法。 该文档还介绍了如何将Python解释器嵌入到另一个应用程序中,用作扩展语言。 最后,它显示了如何编译和链接扩展模块,以便在底层操作系统支持此功能时,可以将动态(运行时)加载到解释器中。

本文档假设有关Python的基本知识。 有关语言的非正式介绍,请参阅Python教程 Python语言参考给出了更正式的语言定义。 Python标准库记录了现有的对象类型,功能和模块(内置并以Python编写),为语言提供了广泛的应用范围。

有关整个Python / C API的详细说明,请参阅单独的Python / C API参考手册

Embedding the CPython runtime in a larger application

Sometimes, rather than creating an extension that runs inside the Python interpreter as the main application, it is desirable to instead embed the CPython runtime inside a larger application. This section covers some of the details involved in doing that successfully.