Search results
2 days ago · This manual documents the API used by C and C++ programmers who want to write extension modules or embed Python. It is a companion to Extending and Embedding the Python Interpreter, which describes the general principles of extension writing but does not document the API functions in detail.
- Importing Modules
PyObject * PyImport_Import (PyObject * name) ¶ Return value:...
- Introduction
The API is equally usable from C++, but for brevity it is...
- Reflection
Equivalent to calling globals() in Python code. Added in...
- Mapping Protocol
This page is licensed under the Python Software Foundation...
- Buffer Protocol
PyBUF_WRITABLE can be |’d to any of the flags in the next...
- Operating System Utilities
void PyOS_AfterFork_Parent ¶ Part of the Stable ABI on...
- Importing Modules
Sep 14, 2020 · The Python/C API allows C programmers to embed Python directly into C code by exposing aspects of CPython internals. It provides direct access to the Python interpreter from C, acting as a...
- Introduction to CPython. When you type python at the console or install a Python distribution from python.org, you are running CPython. CPython is one of the many Python runtimes, maintained and written by different teams of developers.
- The Python Interpreter Process. Now that you’ve seen the Python grammar and memory management, you can follow the process from typing python to the part where your code is executed.
- The CPython Compiler and Execution Loop. In Part 2, you saw how the CPython interpreter takes an input, such as a file or string, and converts it into a logical Abstract Syntax Tree.
- Objects in CPython. CPython comes with a collection of basic types like strings, lists, tuples, dictionaries, and objects. All of these types are built-in.
- A Simple Example¶ Let’s create an extension module called spam (the favorite food of Monty Python fans…) and let’s say we want to create a Python interface to the C library function system() [1].
- Intermezzo: Errors and Exceptions¶ An important convention throughout the Python interpreter is the following: when a function fails, it should set an exception condition and return an error value (usually -1 or a NULL pointer).
- Back to the Example¶ Going back to our example function, you should now be able to understand this statement: if (!PyArg_ParseTuple(args, "s", &command)) return NULL;
- The Module’s Method Table and Initialization Function¶ I promised to show how spam_system() is called from Python programs. First, we need to list its name and address in a “method table”
The Application Programmer's Interface to Python gives C and C++ programmers access to the Python interpreter at a variety of levels. The API is equally usable from C++, but for brevity it is generally referred to as the Python/C API. There are two fundamentally different reasons for using the Python/C API.
The CPython interpreter (aka, "python") works by compiling Python source code to intermediate bytecodes, and then operating on those. CPython, which is written in C, is also accompanied by an Application Programming Interface (API) that enables communication between Python and C (and thus basically to any other language that C can interoperate ...
People also ask
What is the Python/C API?
What is CPython source code?
What is a Python API manual?
Is CPython written in C?
What is CPython runtime?
Does CPython compile code?
This manual documents the API used by C and C++ programmers who want to write extension modules or embed Python. It is a companion to Extending and Embedding the Python Interpreter , which describes the general principles of extension writing but does not document the API functions in detail.